From d0c97e9eb57126e38b7b018a101df1ecb1ad12b8 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 31 Jul 2021 01:41:35 +0900 Subject: [PATCH] Fix #9504: autodoc: generate incorrect reference to the parent class Autodoc generates incorrect references to the parent class the target class inherites the class having `_name` attribute. It conciders the parent is a kind of SpecialForm'ed class by mistake. This uses `isinstance(X, SpecialForm)` to check that. Note: SpecialForm became a class since Python 3.7. --- CHANGES | 2 ++ sphinx/util/typing.py | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 012d32e524..f856950bf2 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__)