Skip to content

Commit e3a8ee9

Browse files
authored
Merge pull request #9538 from tk0miya/9537_GenericAlias
Fix #9537: autodoc: Some typing.* objects are broken
2 parents 650730d + 648af37 commit e3a8ee9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Bugs fixed
1818

1919
* #9504: autodoc: generate incorrect reference to the parent class if the target
2020
class inherites the class having ``_name`` attribute
21+
* #9537: autodoc: Some objects under ``typing`` module are not displayed well
22+
with the HEAD of 3.10
2123
* #9512: sphinx-build: crashed with the HEAD of Python 3.10
2224

2325
Testing

sphinx/util/typing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ def _restify_py37(cls: Optional[Type]) -> str:
148148
args = ', '.join(restify(a) for a in cls.__args__)
149149
return ':obj:`~typing.Union`\\ [%s]' % args
150150
elif inspect.isgenericalias(cls):
151-
if getattr(cls, '_name', None):
151+
if isinstance(cls.__origin__, typing._SpecialForm):
152+
text = restify(cls.__origin__) # type: ignore
153+
elif getattr(cls, '_name', None):
152154
if cls.__module__ == 'typing':
153155
text = ':class:`~%s.%s`' % (cls.__module__, cls._name)
154156
else:
@@ -344,7 +346,7 @@ def _stringify_py37(annotation: Any) -> str:
344346
if not isinstance(annotation.__args__, (list, tuple)):
345347
# broken __args__ found
346348
pass
347-
elif qualname == 'Union':
349+
elif qualname in ('Optional', 'Union'):
348350
if len(annotation.__args__) > 1 and annotation.__args__[-1] is NoneType:
349351
if len(annotation.__args__) > 2:
350352
args = ', '.join(stringify(a) for a in annotation.__args__[:-1])

0 commit comments

Comments
 (0)