Merge pull request #8459 from tk0miya/8452_autodoc_type_aliases_with_autodoc_typehints

Fix #8452: autodoc_type_aliases doesn't work with autodoc_typehints
This commit is contained in:
Takeshi KOMIYA 2020-11-22 01:34:31 +09:00 committed by GitHub
commit ad804647b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -47,6 +47,8 @@ Bugs fixed
type annotated variables type annotated variables
* #8443: autodoc: autoattribute directive can't create document for PEP-526 * #8443: autodoc: autoattribute directive can't create document for PEP-526
based uninitalized variables based uninitalized variables
* #8452: autodoc: autodoc_type_aliases doesn't work when autodoc_typehints is
set to "description"
* #8419: html search: Do not load ``language_data.js`` in non-search pages * #8419: html search: Do not load ``language_data.js`` in non-search pages
* #8454: graphviz: The layout option for graph and digraph directives don't work * #8454: graphviz: The layout option for graph and digraph directives don't work
* #8437: Makefile: ``make clean`` with empty BUILDDIR is dangerous * #8437: Makefile: ``make clean`` with empty BUILDDIR is dangerous

View File

@ -27,7 +27,7 @@ def record_typehints(app: Sphinx, objtype: str, name: str, obj: Any,
if callable(obj): if callable(obj):
annotations = app.env.temp_data.setdefault('annotations', {}) annotations = app.env.temp_data.setdefault('annotations', {})
annotation = annotations.setdefault(name, OrderedDict()) annotation = annotations.setdefault(name, OrderedDict())
sig = inspect.signature(obj) sig = inspect.signature(obj, type_aliases=app.config.autodoc_type_aliases)
for param in sig.parameters.values(): for param in sig.parameters.values():
if param.annotation is not param.empty: if param.annotation is not param.empty:
annotation[param.name] = typing.stringify(param.annotation) annotation[param.name] = typing.stringify(param.annotation)

View File

@ -778,6 +778,28 @@ def test_autodoc_type_aliases(app):
] ]
@pytest.mark.skipif(sys.version_info < (3, 7), reason='python 3.7+ is required.')
@pytest.mark.sphinx('text', testroot='ext-autodoc',
srcdir='autodoc_typehints_description_and_type_aliases',
confoverrides={'autodoc_typehints': "description",
'autodoc_type_aliases': {'myint': 'myint'}})
def test_autodoc_typehints_description_and_type_aliases(app):
(app.srcdir / 'annotations.rst').write_text('.. autofunction:: target.annotations.sum')
app.build()
context = (app.outdir / 'annotations.txt').read_text()
assert ('target.annotations.sum(x, y)\n'
'\n'
' docstring\n'
'\n'
' Parameters:\n'
' * **x** (*myint*) --\n'
'\n'
' * **y** (*myint*) --\n'
'\n'
' Return type:\n'
' myint\n' == context)
@pytest.mark.sphinx('html', testroot='ext-autodoc') @pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_default_options(app): def test_autodoc_default_options(app):
# no settings # no settings