Fix #9490: autodoc: Some typing.* objects are broken

At the HEAD of 3.10, the implementation of `typing._SpecialForm` and
`typing._BaseGenericAlias` has been changed to support __qualname__.
This commit is contained in:
Takeshi KOMIYA
2021-07-23 01:35:20 +09:00
parent 771507e073
commit 68fb54806f
2 changed files with 8 additions and 6 deletions

View File

@@ -21,6 +21,8 @@ Bugs fixed
* #9489: autodoc: Custom types using ``typing.NewType`` are not displayed well
with the HEAD of 3.10
* #9490: autodoc: Some objects under ``typing`` module are not displayed well
with the HEAD of 3.10
* #9435: linkcheck: Failed to check anchors in github.com
Testing

View File

@@ -171,17 +171,17 @@ def _restify_py37(cls: Optional[Type]) -> str:
text += r"\ [%s]" % ", ".join(restify(a) for a in cls.__args__)
return text
elif hasattr(cls, '__qualname__'):
if cls.__module__ == 'typing':
return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
else:
return ':class:`%s.%s`' % (cls.__module__, cls.__qualname__)
elif hasattr(cls, '_name'):
# SpecialForm
if cls.__module__ == 'typing':
return ':obj:`~%s.%s`' % (cls.__module__, cls._name)
else:
return ':obj:`%s.%s`' % (cls.__module__, cls._name)
elif hasattr(cls, '__qualname__'):
if cls.__module__ == 'typing':
return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
else:
return ':class:`%s.%s`' % (cls.__module__, cls.__qualname__)
elif isinstance(cls, ForwardRef):
return ':class:`%s`' % cls.__forward_arg__
else:
@@ -309,7 +309,7 @@ def stringify(annotation: Any) -> str:
elif annotation in INVALID_BUILTIN_CLASSES:
return INVALID_BUILTIN_CLASSES[annotation]
elif (getattr(annotation, '__module__', None) == 'builtins' and
hasattr(annotation, '__qualname__')):
getattr(annotation, '__qualname__', None)):
return annotation.__qualname__
elif annotation is Ellipsis:
return '...'