Fix #10279: autodoc: Default values are rendered as a string literal

When processing overloaded functions, autodoc unexpectedly renders its
default values for kwonlyargs as a string literal unexpectedly
This commit is contained in:
Takeshi KOMIYA 2022-04-01 02:25:04 +09:00
parent 223b1a94f2
commit 82c9a7eb12
2 changed files with 6 additions and 1 deletions

View File

@ -65,6 +65,8 @@ Features added
Bugs fixed
----------
* #10279: autodoc: Default values for keyword only arguments in overloaded
functions are rendered as a string literal
* #10236: html search: objects are duplicated in search result
* #9962: texinfo: Deprecation message for ``@definfoenclose`` command on
bulding texinfo document

View File

@ -775,7 +775,10 @@ def signature_from_ast(node: ast.FunctionDef, code: str = '') -> inspect.Signatu
annotation=annotation))
for i, arg in enumerate(args.kwonlyargs):
default = ast_unparse(args.kw_defaults[i], code) or Parameter.empty # type: ignore
if args.kw_defaults[i] is None:
default = Parameter.empty
else:
default = DefaultValue(ast_unparse(args.kw_defaults[i], code)) # type: ignore # NOQA
annotation = ast_unparse(arg.annotation, code) or Parameter.empty
params.append(Parameter(arg.arg, Parameter.KEYWORD_ONLY, default=default,
annotation=annotation))