Skip to content

Commit

Permalink
Fix sphinx-doc#10015: autodoc: autodoc_typehints_format='short' does …
Browse files Browse the repository at this point in the history
…not work when autodoc_typehints='description'
  • Loading branch information
tk0miya committed Dec 26, 2021
1 parent e5ccf91 commit e04faf9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sphinx/ext/autodoc/typehints.py
Expand Up @@ -23,16 +23,21 @@
def record_typehints(app: Sphinx, objtype: str, name: str, obj: Any,
options: Dict, args: str, retann: str) -> None:
"""Record type hints to env object."""
if app.config.autodoc_typehints_format == 'short':
mode = 'smart'
else:
mode = 'fully-qualified'

try:
if callable(obj):
annotations = app.env.temp_data.setdefault('annotations', {})
annotation = annotations.setdefault(name, OrderedDict())
sig = inspect.signature(obj, type_aliases=app.config.autodoc_type_aliases)
for param in sig.parameters.values():
if param.annotation is not param.empty:
annotation[param.name] = typing.stringify(param.annotation)
annotation[param.name] = typing.stringify(param.annotation, mode)
if sig.return_annotation is not sig.empty:
annotation['return'] = typing.stringify(sig.return_annotation)
annotation['return'] = typing.stringify(sig.return_annotation, mode)
except (TypeError, ValueError):
pass

Expand Down

0 comments on commit e04faf9

Please sign in to comment.