Skip to content

Commit 75c86c3

Browse files
committed
Merge branch '4.1.x' into 4.x
2 parents a7ac325 + e3a8ee9 commit 75c86c3

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ Features added
5656
Bugs fixed
5757
----------
5858

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

6165
Testing

sphinx/util/typing.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ def _restify_py37(cls: Optional[Type]) -> str:
157157
args = ', '.join(restify(a) for a in cls.__args__)
158158
return ':obj:`~typing.Union`\\ [%s]' % args
159159
elif inspect.isgenericalias(cls):
160-
if getattr(cls, '_name', None):
160+
if isinstance(cls.__origin__, typing._SpecialForm):
161+
text = restify(cls.__origin__) # type: ignore
162+
elif getattr(cls, '_name', None):
161163
if cls.__module__ == 'typing':
162164
text = ':class:`~%s.%s`' % (cls.__module__, cls._name)
163165
else:
@@ -180,12 +182,8 @@ def _restify_py37(cls: Optional[Type]) -> str:
180182
text += r"\ [%s]" % ", ".join(restify(a) for a in cls.__args__)
181183

182184
return text
183-
elif hasattr(cls, '_name'):
184-
# SpecialForm
185-
if cls.__module__ == 'typing':
186-
return ':obj:`~%s.%s`' % (cls.__module__, cls._name)
187-
else:
188-
return ':obj:`%s.%s`' % (cls.__module__, cls._name)
185+
elif isinstance(cls, typing._SpecialForm):
186+
return ':obj:`~%s.%s`' % (cls.__module__, cls._name)
189187
elif hasattr(cls, '__qualname__'):
190188
if cls.__module__ == 'typing':
191189
return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
@@ -360,7 +358,7 @@ def _stringify_py37(annotation: Any) -> str:
360358
if not isinstance(annotation.__args__, (list, tuple)):
361359
# broken __args__ found
362360
pass
363-
elif qualname == 'Union':
361+
elif qualname in ('Optional', 'Union'):
364362
if len(annotation.__args__) > 1 and annotation.__args__[-1] is NoneType:
365363
if len(annotation.__args__) > 2:
366364
args = ', '.join(stringify(a) for a in annotation.__args__[:-1])

0 commit comments

Comments
 (0)