diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-12-17 00:32:59 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-12-17 00:46:42 +0900 |
commit | 36e684bf83d14e587f0bf48eb0980f41ab66733e (patch) | |
tree | fb771f1d6b15f210c8c55aaa175b385a00fb7266 /sphinx/util/inspect.py | |
parent | bec552c3efa9ce452dea8549c517428fcb98f30d (diff) | |
download | sphinx-git-36e684bf83d14e587f0bf48eb0980f41ab66733e.tar.gz |
refactor: Move _getmro() to sphinx.util.inspect module
Diffstat (limited to 'sphinx/util/inspect.py')
-rw-r--r-- | sphinx/util/inspect.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index df469a5ae..a26c818c0 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -36,6 +36,10 @@ else: MethodDescriptorType = type(str.join) WrapperDescriptorType = type(dict.__dict__['fromkeys']) +if False: + # For type annotation + from typing import Type # NOQA + logger = logging.getLogger(__name__) 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 {} +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]: """Get __slots__ attribute of the class as dict. |