Skip to content

Commit

Permalink
改进 hub help_part 显示默认参数
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Feb 24, 2025
1 parent 713359d commit 928eb8b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion hikyuu/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pathlib
import logging
import importlib
import inspect
from configparser import ConfigParser

# 引入 git 前需设置环境变量,否则某些情况下会报错失败
Expand Down Expand Up @@ -462,11 +463,21 @@ def get_part_info(self, name):
part_module = importlib.import_module(part_model.module_name)
except ModuleNotFoundError:
raise PartNotFoundError(name, '请检查部件对应路径是否存在')
signature = inspect.signature(part_module.part)
func_name = f'\npart("{name}",'
for param_name, param in signature.parameters.items():
if param.default is param.empty:
func_name += f"{param_name}, "
else:
default_value = param.default
func_name += f"{param_name}={default_value}, "
func_name += ")\n"
func_name += part_module.part.__doc__
return {
'name': name,
'author': part_model.author,
'version': part_model.version,
'doc': part_module.part.__doc__,
'doc': func_name # part_module.part.__doc__,
}

def print_part_info(self, name):
Expand Down

0 comments on commit 928eb8b

Please sign in to comment.