refactor: Simplify stringify_signature()

This commit is contained in:
Takeshi KOMIYA 2020-01-11 02:33:12 +09:00
parent 6fa592f111
commit adaa566cc5

View File

@ -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): elif param.kind == param.VAR_KEYWORD:
arg.write('**' + param.name)
else:
arg.write(param.name) arg.write(param.name)
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)) arg.write(stringify_annotation(param.annotation))
if param.default is not param.empty: 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(object_description(param.default))
else: else:
arg.write('=') arg.write('=')
arg.write(object_description(param.default)) 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:
arg.write('**')
arg.write(param.name)
if show_annotation and param.annotation is not param.empty:
arg.write(': ')
arg.write(stringify_annotation(param.annotation))
args.append(arg.getvalue()) args.append(arg.getvalue())
last_kind = param.kind last_kind = param.kind