mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge branch '4.x' into 9479_autodoc_mocked_target
This commit is contained in:
commit
585869ac59
3
CHANGES
3
CHANGES
@ -22,6 +22,7 @@ Bugs fixed
|
|||||||
----------
|
----------
|
||||||
|
|
||||||
* #9487: autodoc: typehint for cached_property is not shown
|
* #9487: autodoc: typehint for cached_property is not shown
|
||||||
|
* #9509: autodoc: AttributeError is raised on failed resolving typehints
|
||||||
* #9481: autosummary: some warnings contain non-existing filenames
|
* #9481: autosummary: some warnings contain non-existing filenames
|
||||||
* #9481: c domain: some warnings contain non-existing filenames
|
* #9481: c domain: some warnings contain non-existing filenames
|
||||||
* #9481: cpp domain: some warnings contain non-existing filenames
|
* #9481: cpp domain: some warnings contain non-existing filenames
|
||||||
@ -47,6 +48,8 @@ Features added
|
|||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* #9512: sphinx-build: crashed with the HEAD of Python 3.10
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@ else:
|
|||||||
ref = _ForwardRef(self.arg)
|
ref = _ForwardRef(self.arg)
|
||||||
return ref._eval_type(globalns, localns)
|
return ref._eval_type(globalns, localns)
|
||||||
|
|
||||||
if sys.version_info > (3, 10):
|
try:
|
||||||
from types import Union as types_Union
|
from types import UnionType # type: ignore # python 3.10 or above
|
||||||
else:
|
except ImportError:
|
||||||
types_Union = None
|
UnionType = None
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
@ -86,6 +86,9 @@ def get_type_hints(obj: Any, globalns: Dict = None, localns: Dict = None) -> Dic
|
|||||||
except NameError:
|
except NameError:
|
||||||
# Failed to evaluate ForwardRef (maybe TYPE_CHECKING)
|
# Failed to evaluate ForwardRef (maybe TYPE_CHECKING)
|
||||||
return safe_getattr(obj, '__annotations__', {})
|
return safe_getattr(obj, '__annotations__', {})
|
||||||
|
except AttributeError:
|
||||||
|
# Failed to evaluate ForwardRef (maybe not runtime checkable)
|
||||||
|
return safe_getattr(obj, '__annotations__', {})
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Invalid object is given. But try to get __annotations__ as a fallback for
|
# Invalid object is given. But try to get __annotations__ as a fallback for
|
||||||
# the code using type union operator (PEP 604) in python 3.9 or below.
|
# the code using type union operator (PEP 604) in python 3.9 or below.
|
||||||
@ -114,7 +117,7 @@ def restify(cls: Optional[Type]) -> str:
|
|||||||
return ':class:`%s`' % INVALID_BUILTIN_CLASSES[cls]
|
return ':class:`%s`' % INVALID_BUILTIN_CLASSES[cls]
|
||||||
elif inspect.isNewType(cls):
|
elif inspect.isNewType(cls):
|
||||||
return ':class:`%s`' % cls.__name__
|
return ':class:`%s`' % cls.__name__
|
||||||
elif types_Union and isinstance(cls, types_Union):
|
elif UnionType and isinstance(cls, UnionType):
|
||||||
if len(cls.__args__) > 1 and None in cls.__args__:
|
if len(cls.__args__) > 1 and None in cls.__args__:
|
||||||
args = ' | '.join(restify(a) for a in cls.__args__ if a)
|
args = ' | '.join(restify(a) for a in cls.__args__ if a)
|
||||||
return 'Optional[%s]' % args
|
return 'Optional[%s]' % args
|
||||||
@ -340,7 +343,7 @@ def _stringify_py37(annotation: Any) -> str:
|
|||||||
elif hasattr(annotation, '__origin__'):
|
elif hasattr(annotation, '__origin__'):
|
||||||
# instantiated generic provided by a user
|
# instantiated generic provided by a user
|
||||||
qualname = stringify(annotation.__origin__)
|
qualname = stringify(annotation.__origin__)
|
||||||
elif types_Union and isinstance(annotation, types_Union): # types.Union (for py3.10+)
|
elif UnionType and isinstance(annotation, UnionType): # types.Union (for py3.10+)
|
||||||
qualname = 'types.Union'
|
qualname = 'types.Union'
|
||||||
else:
|
else:
|
||||||
# we weren't able to extract the base type, appending arguments would
|
# we weren't able to extract the base type, appending arguments would
|
||||||
|
Loading…
Reference in New Issue
Block a user