Skip to content

Commit

Permalink
Fix sphinx-doc#9504: autodoc: generate incorrect reference to the par…
Browse files Browse the repository at this point in the history
…ent 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.
  • Loading branch information
tk0miya committed Jul 30, 2021
1 parent 1fd5f74 commit d0c97e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions sphinx/util/typing.py
Expand Up @@ -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__)
Expand Down

0 comments on commit d0c97e9

Please sign in to comment.