Skip to content

Commit

Permalink
Fix #9489: autodoc: Custom types using typing.NewType are broken
Browse files Browse the repository at this point in the history
At the HEAD of 3.10, the implementation of ``typing.NewType`` has been
changed to the class based.  To follow the change, this uses
``isinstance`` on ``sphinx.util.inspect:isNewType()`.
  • Loading branch information
tk0miya committed Jul 22, 2021
1 parent 9ebdc98 commit 771507e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -19,6 +19,8 @@ Features added
Bugs fixed
----------

* #9489: autodoc: Custom types using ``typing.NewType`` are not displayed well
with the HEAD of 3.10
* #9435: linkcheck: Failed to check anchors in github.com

Testing
Expand Down
13 changes: 8 additions & 5 deletions sphinx/util/inspect.py
Expand Up @@ -211,12 +211,15 @@ def getslots(obj: Any) -> Optional[Dict]:

def isNewType(obj: Any) -> bool:
"""Check the if object is a kind of NewType."""
__module__ = safe_getattr(obj, '__module__', None)
__qualname__ = safe_getattr(obj, '__qualname__', None)
if __module__ == 'typing' and __qualname__ == 'NewType.<locals>.new_type':
return True
if sys.version_info >= (3, 10):
return isinstance(obj, typing.NewType)
else:
return False
__module__ = safe_getattr(obj, '__module__', None)
__qualname__ = safe_getattr(obj, '__qualname__', None)
if __module__ == 'typing' and __qualname__ == 'NewType.<locals>.new_type':
return True
else:
return False


def isenumclass(x: Any) -> bool:
Expand Down

0 comments on commit 771507e

Please sign in to comment.