mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: Simplify stringify_signature()
This commit is contained in:
parent
6fa592f111
commit
adaa566cc5
@ -382,32 +382,22 @@ def stringify_signature(sig: inspect.Signature, show_annotation: bool = True,
|
|||||||
args.append('*')
|
args.append('*')
|
||||||
|
|
||||||
arg = StringIO()
|
arg = StringIO()
|
||||||
if param.kind in (param.POSITIONAL_ONLY,
|
if param.kind == param.VAR_POSITIONAL:
|
||||||
param.POSITIONAL_OR_KEYWORD,
|
arg.write('*' + param.name)
|
||||||
param.KEYWORD_ONLY):
|
|
||||||
arg.write(param.name)
|
|
||||||
if show_annotation and param.annotation is not param.empty:
|
|
||||||
arg.write(': ')
|
|
||||||
arg.write(stringify_annotation(param.annotation))
|
|
||||||
if param.default is not param.empty:
|
|
||||||
if show_annotation and param.annotation is not param.empty:
|
|
||||||
arg.write(' = ')
|
|
||||||
arg.write(object_description(param.default))
|
|
||||||
else:
|
|
||||||
arg.write('=')
|
|
||||||
arg.write(object_description(param.default))
|
|
||||||
elif param.kind == param.VAR_POSITIONAL:
|
|
||||||
arg.write('*')
|
|
||||||
arg.write(param.name)
|
|
||||||
if show_annotation and param.annotation is not param.empty:
|
|
||||||
arg.write(': ')
|
|
||||||
arg.write(stringify_annotation(param.annotation))
|
|
||||||
elif param.kind == param.VAR_KEYWORD:
|
elif param.kind == param.VAR_KEYWORD:
|
||||||
arg.write('**')
|
arg.write('**' + param.name)
|
||||||
|
else:
|
||||||
arg.write(param.name)
|
arg.write(param.name)
|
||||||
|
|
||||||
|
if show_annotation and param.annotation is not param.empty:
|
||||||
|
arg.write(': ')
|
||||||
|
arg.write(stringify_annotation(param.annotation))
|
||||||
|
if param.default is not param.empty:
|
||||||
if show_annotation and param.annotation is not param.empty:
|
if show_annotation and param.annotation is not param.empty:
|
||||||
arg.write(': ')
|
arg.write(' = ')
|
||||||
arg.write(stringify_annotation(param.annotation))
|
else:
|
||||||
|
arg.write('=')
|
||||||
|
arg.write(object_description(param.default))
|
||||||
|
|
||||||
args.append(arg.getvalue())
|
args.append(arg.getvalue())
|
||||||
last_kind = param.kind
|
last_kind = param.kind
|
||||||
|
Loading…
Reference in New Issue
Block a user