Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-12-16 18:32:59 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-12-16 18:46:42 +0300
commit36e684bf83d14e587f0bf48eb0980f41ab66733e (patch)
treefb771f1d6b15f210c8c55aaa175b385a00fb7266 /sphinx/util
parentbec552c3efa9ce452dea8549c517428fcb98f30d (diff)
refactor: Move _getmro() to sphinx.util.inspect module
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/inspect.py16
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.