Skip to content

Commit 68fb548

Browse files
committed
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__.
1 parent 771507e commit 68fb548

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Bugs fixed
2121

2222
* #9489: autodoc: Custom types using ``typing.NewType`` are not displayed well
2323
with the HEAD of 3.10
24+
* #9490: autodoc: Some objects under ``typing`` module are not displayed well
25+
with the HEAD of 3.10
2426
* #9435: linkcheck: Failed to check anchors in github.com
2527

2628
Testing

sphinx/util/typing.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ def _restify_py37(cls: Optional[Type]) -> str:
171171
text += r"\ [%s]" % ", ".join(restify(a) for a in cls.__args__)
172172

173173
return text
174-
elif hasattr(cls, '__qualname__'):
175-
if cls.__module__ == 'typing':
176-
return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
177-
else:
178-
return ':class:`%s.%s`' % (cls.__module__, cls.__qualname__)
179174
elif hasattr(cls, '_name'):
180175
# SpecialForm
181176
if cls.__module__ == 'typing':
182177
return ':obj:`~%s.%s`' % (cls.__module__, cls._name)
183178
else:
184179
return ':obj:`%s.%s`' % (cls.__module__, cls._name)
180+
elif hasattr(cls, '__qualname__'):
181+
if cls.__module__ == 'typing':
182+
return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
183+
else:
184+
return ':class:`%s.%s`' % (cls.__module__, cls.__qualname__)
185185
elif isinstance(cls, ForwardRef):
186186
return ':class:`%s`' % cls.__forward_arg__
187187
else:
@@ -309,7 +309,7 @@ def stringify(annotation: Any) -> str:
309309
elif annotation in INVALID_BUILTIN_CLASSES:
310310
return INVALID_BUILTIN_CLASSES[annotation]
311311
elif (getattr(annotation, '__module__', None) == 'builtins' and
312-
hasattr(annotation, '__qualname__')):
312+
getattr(annotation, '__qualname__', None)):
313313
return annotation.__qualname__
314314
elif annotation is Ellipsis:
315315
return '...'

0 commit comments

Comments
 (0)