Fix #9489: autodoc: Custom types using typing.NewType are broken

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()`.
This commit is contained in:
Takeshi KOMIYA 2021-07-23 00:06:33 +09:00
parent 9ebdc987b0
commit 771507e073
2 changed files with 10 additions and 5 deletions

View File

@ -19,6 +19,8 @@ Features added
Bugs fixed 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 * #9435: linkcheck: Failed to check anchors in github.com
Testing Testing

View File

@ -211,12 +211,15 @@ def getslots(obj: Any) -> Optional[Dict]:
def isNewType(obj: Any) -> bool: def isNewType(obj: Any) -> bool:
"""Check the if object is a kind of NewType.""" """Check the if object is a kind of NewType."""
__module__ = safe_getattr(obj, '__module__', None) if sys.version_info >= (3, 10):
__qualname__ = safe_getattr(obj, '__qualname__', None) return isinstance(obj, typing.NewType)
if __module__ == 'typing' and __qualname__ == 'NewType.<locals>.new_type':
return True
else: 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: def isenumclass(x: Any) -> bool: