mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #10015: autodoc: autodoc_typehints_format='short' does not work when autodoc_typehints='description'
This commit is contained in:
@@ -23,6 +23,11 @@ from sphinx.util import inspect, typing
|
||||
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', {})
|
||||
@@ -30,9 +35,9 @@ def record_typehints(app: Sphinx, objtype: str, name: str, obj: Any,
|
||||
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
|
||||
|
||||
|
||||
@@ -835,7 +835,7 @@ def test_autodoc_typehints_description(app):
|
||||
' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) --\n'
|
||||
'\n'
|
||||
' Return type:\n'
|
||||
' Tuple[int, int]\n'
|
||||
' *Tuple*[int, int]\n'
|
||||
in context)
|
||||
|
||||
# Overloads still get displayed in the signature
|
||||
@@ -887,7 +887,7 @@ def test_autodoc_typehints_description_no_undoc(app):
|
||||
' another tuple\n'
|
||||
'\n'
|
||||
' Return type:\n'
|
||||
' Tuple[int, int]\n'
|
||||
' *Tuple*[int, int]\n'
|
||||
in context)
|
||||
|
||||
|
||||
@@ -978,7 +978,7 @@ def test_autodoc_typehints_both(app):
|
||||
' **x** (*Tuple**[**int**, **Union**[**int**, **str**]**]*) --\n'
|
||||
'\n'
|
||||
' Return type:\n'
|
||||
' Tuple[int, int]\n'
|
||||
' *Tuple*[int, int]\n'
|
||||
in context)
|
||||
|
||||
# Overloads still get displayed in the signature
|
||||
|
||||
Reference in New Issue
Block a user