mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #9491 from tk0miya/9489_NewType
Bugfix for HEAD of python-3.10
This commit is contained in:
commit
9218ad4adc
4
CHANGES
4
CHANGES
@ -19,6 +19,10 @@ Features added
|
|||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* #9489: autodoc: Custom types using ``typing.NewType`` are not displayed well
|
||||||
|
with the HEAD of 3.10
|
||||||
|
* #9490: autodoc: Some objects under ``typing`` module 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
|
||||||
|
@ -211,6 +211,9 @@ 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."""
|
||||||
|
if sys.version_info >= (3, 10):
|
||||||
|
return isinstance(obj, typing.NewType)
|
||||||
|
else:
|
||||||
__module__ = safe_getattr(obj, '__module__', None)
|
__module__ = safe_getattr(obj, '__module__', None)
|
||||||
__qualname__ = safe_getattr(obj, '__qualname__', None)
|
__qualname__ = safe_getattr(obj, '__qualname__', None)
|
||||||
if __module__ == 'typing' and __qualname__ == 'NewType.<locals>.new_type':
|
if __module__ == 'typing' and __qualname__ == 'NewType.<locals>.new_type':
|
||||||
|
@ -171,17 +171,17 @@ def _restify_py37(cls: Optional[Type]) -> str:
|
|||||||
text += r"\ [%s]" % ", ".join(restify(a) for a in cls.__args__)
|
text += r"\ [%s]" % ", ".join(restify(a) for a in cls.__args__)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
elif hasattr(cls, '__qualname__'):
|
|
||||||
if cls.__module__ == 'typing':
|
|
||||||
return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
|
|
||||||
else:
|
|
||||||
return ':class:`%s.%s`' % (cls.__module__, cls.__qualname__)
|
|
||||||
elif hasattr(cls, '_name'):
|
elif hasattr(cls, '_name'):
|
||||||
# SpecialForm
|
# SpecialForm
|
||||||
if cls.__module__ == 'typing':
|
if cls.__module__ == 'typing':
|
||||||
return ':obj:`~%s.%s`' % (cls.__module__, cls._name)
|
return ':obj:`~%s.%s`' % (cls.__module__, cls._name)
|
||||||
else:
|
else:
|
||||||
return ':obj:`%s.%s`' % (cls.__module__, cls._name)
|
return ':obj:`%s.%s`' % (cls.__module__, cls._name)
|
||||||
|
elif hasattr(cls, '__qualname__'):
|
||||||
|
if cls.__module__ == 'typing':
|
||||||
|
return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
|
||||||
|
else:
|
||||||
|
return ':class:`%s.%s`' % (cls.__module__, cls.__qualname__)
|
||||||
elif isinstance(cls, ForwardRef):
|
elif isinstance(cls, ForwardRef):
|
||||||
return ':class:`%s`' % cls.__forward_arg__
|
return ':class:`%s`' % cls.__forward_arg__
|
||||||
else:
|
else:
|
||||||
@ -309,7 +309,7 @@ def stringify(annotation: Any) -> str:
|
|||||||
elif annotation in INVALID_BUILTIN_CLASSES:
|
elif annotation in INVALID_BUILTIN_CLASSES:
|
||||||
return INVALID_BUILTIN_CLASSES[annotation]
|
return INVALID_BUILTIN_CLASSES[annotation]
|
||||||
elif (getattr(annotation, '__module__', None) == 'builtins' and
|
elif (getattr(annotation, '__module__', None) == 'builtins' and
|
||||||
hasattr(annotation, '__qualname__')):
|
getattr(annotation, '__qualname__', None)):
|
||||||
return annotation.__qualname__
|
return annotation.__qualname__
|
||||||
elif annotation is Ellipsis:
|
elif annotation is Ellipsis:
|
||||||
return '...'
|
return '...'
|
||||||
|
Loading…
Reference in New Issue
Block a user