未验证 提交 96add8a4 编写于 作者: Z Zeng Jinle 提交者: GitHub

fix print_signatures.py when defaults=None, test=develop, test=document_fix (#23784)

上级 532079a2
...@@ -53,19 +53,23 @@ def get_functools_partial_spec(func): ...@@ -53,19 +53,23 @@ def get_functools_partial_spec(func):
return '{}(args={}, keywords={})'.format(func_str, args, keywords) return '{}(args={}, keywords={})'.format(func_str, args, keywords)
def format_spec_doc(spec, doc=None): def format_spec(spec):
args = spec.args args = spec.args
varargs = spec.varargs varargs = spec.varargs
keywords = spec.keywords keywords = spec.keywords
defaults = list(spec.defaults) defaults = spec.defaults
for idx, item in enumerate(defaults): if defaults is not None:
if not isinstance(item, functools.partial): defaults = list(defaults)
continue for idx, item in enumerate(defaults):
if not isinstance(item, functools.partial):
continue
defaults[idx] = get_functools_partial_spec(item)
defaults[idx] = get_functools_partial_spec(item) defaults = tuple(defaults)
return 'ArgSpec(args={}, varargs={}, keywords={}, defaults={})'.format( return 'ArgSpec(args={}, varargs={}, keywords={}, defaults={})'.format(
args, varargs, keywords, tuple(defaults)) args, varargs, keywords, defaults)
def queue_dict(member, cur_name): def queue_dict(member, cur_name):
...@@ -78,12 +82,18 @@ def queue_dict(member, cur_name): ...@@ -78,12 +82,18 @@ def queue_dict(member, cur_name):
args = member.__module__ + "." + member.__name__ args = member.__module__ + "." + member.__name__
else: else:
try: try:
args = format_spec_doc(inspect.getargspec(member)) args = inspect.getargspec(member)
has_type_error = False
except TypeError: # special for PyBind method except TypeError: # special for PyBind method
args = " ".join([ args = " ".join([
line.strip() for line in pydoc.render_doc(member).split('\n') line.strip() for line in pydoc.render_doc(member).split('\n')
if "->" in line if "->" in line
]) ])
has_type_error = True
if not has_type_error:
args = format_spec(args)
member_dict[cur_name] = "({}, ('document', '{}'))".format(args, doc_md5) member_dict[cur_name] = "({}, ('document', '{}'))".format(args, doc_md5)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册