Skip to content

Commit

Permalink
Merge pull request #9538 from tk0miya/9537_GenericAlias
Browse files Browse the repository at this point in the history
Fix #9537: autodoc: Some typing.* objects are broken
  • Loading branch information
tk0miya committed Aug 10, 2021
2 parents 650730d + 648af37 commit e3a8ee9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -18,6 +18,8 @@ Bugs fixed

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

Testing
Expand Down
6 changes: 4 additions & 2 deletions sphinx/util/typing.py
Expand Up @@ -148,7 +148,9 @@ def _restify_py37(cls: Optional[Type]) -> str:
args = ', '.join(restify(a) for a in cls.__args__)
return ':obj:`~typing.Union`\\ [%s]' % args
elif inspect.isgenericalias(cls):
if getattr(cls, '_name', None):
if isinstance(cls.__origin__, typing._SpecialForm):
text = restify(cls.__origin__) # type: ignore
elif getattr(cls, '_name', None):
if cls.__module__ == 'typing':
text = ':class:`~%s.%s`' % (cls.__module__, cls._name)
else:
Expand Down Expand Up @@ -344,7 +346,7 @@ def _stringify_py37(annotation: Any) -> str:
if not isinstance(annotation.__args__, (list, tuple)):
# broken __args__ found
pass
elif qualname == 'Union':
elif qualname in ('Optional', 'Union'):
if len(annotation.__args__) > 1 and annotation.__args__[-1] is NoneType:
if len(annotation.__args__) > 2:
args = ', '.join(stringify(a) for a in annotation.__args__[:-1])
Expand Down

0 comments on commit e3a8ee9

Please sign in to comment.