-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Milestone
Description
Describe the bug
When sphinx.ext.autodoc encounters a type annotation with a parameterized builtin type, e.g. list[int], it does not render the parameterization at all.
The generic parameterized types from typing (e.g. List[int])work as expected, and I would expect to get the same result using the corresponding builtin types from Python 3.9 onwards, as per https://www.python.org/dev/peps/pep-0585/.
How to Reproduce
Assume a Python project with the following structure:
├── docs
│ ├── conf.py
│ └── index.rst
└── src
└── xxx.py
conf.py
import sys
sys.path.insert(0, 'src')
needs_sphinx = '4.1'
extensions = ['sphinx.ext.autodoc']
index.rst
.. autofunction:: xxx.func
.. autofunction:: xxx.Func
xxx.py
from typing import Dict, Set, Type
class A: pass
def func(a: set[type[A]]) -> dict[type[A], int]:
"""test function."""
pass
def Func(a: Set[Type[A]]) -> Dict[Type[A], int]:
"""Test function."""
pass
When I run sphinx-build docs output it builds me an output/index.html which, rendered, looks like
xxx.func(a: set) → dict
test function.
xxx.Func(a: Set[Type[xxx.A]]) → Dict[Type[xxx.A], int]
Test function.
Expected behavior
What I expect to get:
xxx.func(a: set[type[xxx.A]]) → dict[type[xxx.A], int]
test function.
xxx.Func(a: Set[Type[xxx.A]]) → Dict[Type[xxx.A], int]
Test function.
Your project
How can I attach a file?
Screenshots
No response
OS
Ubuntu 20.04
Python version
3.9.6
Sphinx version
4.1.2
Sphinx extensions
sphinx.ext.autodoc
Extra tools
No response
Additional context
No response