diff --git a/CHANGES b/CHANGES index 8fa1a09d0ec..a4a4030711f 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 23dd9e9307f..fedc2aa6a8f 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -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..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..new_type': + return True + else: + return False def isenumclass(x: Any) -> bool: