diff --git a/CHANGES b/CHANGES index 70eb8db93a9..7332a40fb84 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #9504: autodoc: generate incorrect reference to the parent class if the target + class inherites the class having ``_name`` attribute * #9512: sphinx-build: crashed with the HEAD of Python 3.10 Testing diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 012d32e5244..f856950bf23 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -171,12 +171,8 @@ def _restify_py37(cls: Optional[Type]) -> str: text += r"\ [%s]" % ", ".join(restify(a) for a in cls.__args__) return text - 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 isinstance(cls, typing._SpecialForm): + return ':obj:`~%s.%s`' % (cls.__module__, cls._name) elif hasattr(cls, '__qualname__'): if cls.__module__ == 'typing': return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)