mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: Move _getmro() to sphinx.util.inspect module
This commit is contained in:
parent
bec552c3ef
commit
36e684bf83
1
CHANGES
1
CHANGES
@ -23,6 +23,7 @@ Deprecated
|
|||||||
* ``sphinx.ext.autodoc.SlotsAttributeDocumenter``
|
* ``sphinx.ext.autodoc.SlotsAttributeDocumenter``
|
||||||
* ``sphinx.ext.autodoc.TypeVarDocumenter``
|
* ``sphinx.ext.autodoc.TypeVarDocumenter``
|
||||||
* ``sphinx.ext.autodoc.importer._getannotations()``
|
* ``sphinx.ext.autodoc.importer._getannotations()``
|
||||||
|
* ``sphinx.ext.autodoc.importer._getmro()``
|
||||||
* ``sphinx.pycode.ModuleAnalyzer.parse()``
|
* ``sphinx.pycode.ModuleAnalyzer.parse()``
|
||||||
* ``sphinx.util.osutil.movefile()``
|
* ``sphinx.util.osutil.movefile()``
|
||||||
* ``sphinx.util.requests.is_ssl_error()``
|
* ``sphinx.util.requests.is_ssl_error()``
|
||||||
|
@ -72,6 +72,11 @@ The following is a list of deprecated interfaces.
|
|||||||
- 4.0
|
- 4.0
|
||||||
- ``sphinx.util.inspect.getannotations()``
|
- ``sphinx.util.inspect.getannotations()``
|
||||||
|
|
||||||
|
* - ``sphinx.ext.autodoc.importer._getmro()``
|
||||||
|
- 3.4
|
||||||
|
- 4.0
|
||||||
|
- ``sphinx.util.inspect.getmro()``
|
||||||
|
|
||||||
* - ``sphinx.pycode.ModuleAnalyzer.parse()``
|
* - ``sphinx.pycode.ModuleAnalyzer.parse()``
|
||||||
- 3.4
|
- 3.4
|
||||||
- 5.0
|
- 5.0
|
||||||
|
@ -16,7 +16,8 @@ from typing import Any, Callable, Dict, List, Mapping, NamedTuple, Optional, Tup
|
|||||||
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
|
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
|
||||||
from sphinx.pycode import ModuleAnalyzer
|
from sphinx.pycode import ModuleAnalyzer
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
from sphinx.util.inspect import getannotations, getslots, isclass, isenumclass, safe_getattr
|
from sphinx.util.inspect import (getannotations, getmro, getslots, isclass, isenumclass,
|
||||||
|
safe_getattr)
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
@ -165,12 +166,9 @@ Attribute = NamedTuple('Attribute', [('name', str),
|
|||||||
|
|
||||||
|
|
||||||
def _getmro(obj: Any) -> Tuple["Type", ...]:
|
def _getmro(obj: Any) -> Tuple["Type", ...]:
|
||||||
"""Get __mro__ from given *obj* safely."""
|
warnings.warn('sphinx.ext.autodoc.importer._getmro() is deprecated.',
|
||||||
__mro__ = safe_getattr(obj, '__mro__', None)
|
RemovedInSphinx40Warning)
|
||||||
if isinstance(__mro__, tuple):
|
return getmro(obj)
|
||||||
return __mro__
|
|
||||||
else:
|
|
||||||
return tuple()
|
|
||||||
|
|
||||||
|
|
||||||
def _getannotations(obj: Any) -> Mapping[str, Any]:
|
def _getannotations(obj: Any) -> Mapping[str, Any]:
|
||||||
@ -224,7 +222,7 @@ def get_object_members(subject: Any, objpath: List[str], attrgetter: Callable,
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# annotation only member (ex. attr: int)
|
# annotation only member (ex. attr: int)
|
||||||
for i, cls in enumerate(_getmro(subject)):
|
for i, cls in enumerate(getmro(subject)):
|
||||||
try:
|
try:
|
||||||
for name in getannotations(cls):
|
for name in getannotations(cls):
|
||||||
name = unmangle(cls, name)
|
name = unmangle(cls, name)
|
||||||
|
@ -36,6 +36,10 @@ else:
|
|||||||
MethodDescriptorType = type(str.join)
|
MethodDescriptorType = type(str.join)
|
||||||
WrapperDescriptorType = type(dict.__dict__['fromkeys'])
|
WrapperDescriptorType = type(dict.__dict__['fromkeys'])
|
||||||
|
|
||||||
|
if False:
|
||||||
|
# For type annotation
|
||||||
|
from typing import Type # NOQA
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
memory_address_re = re.compile(r' at 0x[0-9a-f]{8,16}(?=>)', re.IGNORECASE)
|
memory_address_re = re.compile(r' at 0x[0-9a-f]{8,16}(?=>)', re.IGNORECASE)
|
||||||
@ -166,6 +170,18 @@ def getannotations(obj: Any) -> Mapping[str, Any]:
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def getmro(obj: Any) -> Tuple["Type", ...]:
|
||||||
|
"""Get __mro__ from given *obj* safely.
|
||||||
|
|
||||||
|
Raises AttributeError if given *obj* raises an error on accessing __mro__.
|
||||||
|
"""
|
||||||
|
__mro__ = safe_getattr(obj, '__mro__', None)
|
||||||
|
if isinstance(__mro__, tuple):
|
||||||
|
return __mro__
|
||||||
|
else:
|
||||||
|
return tuple()
|
||||||
|
|
||||||
|
|
||||||
def getslots(obj: Any) -> Optional[Dict]:
|
def getslots(obj: Any) -> Optional[Dict]:
|
||||||
"""Get __slots__ attribute of the class as dict.
|
"""Get __slots__ attribute of the class as dict.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user