Skip to content

Commit

Permalink
Merge pull request #10315 from tk0miya/10279_defvalue_for_kwonlyargs_…
Browse files Browse the repository at this point in the history
…in_overloads

Fix #10279: autodoc: Default values are rendered as a string literal
  • Loading branch information
tk0miya committed Apr 1, 2022
2 parents 223b1a9 + 82c9a7e commit 9141464
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion sphinx/util/inspect.py
Expand Up @@ -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))
Expand Down

0 comments on commit 9141464

Please sign in to comment.