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>2021-09-20 07:20:26 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-09-20 07:20:26 +0300
commit10b7f0e2522e44fe33f900ef317c25bbadeeb5a0 (patch)
treec186a5cb61cee64b5f922897617a4cff0d960a52 /sphinx/util
parenta05dc0b41992b92fc4e352439a27eddd0f5a88a9 (diff)
Fix #9607: autodoc: Incorrect base class detection
In case of the descendants of generic class, the value of obj.__orig_bases__ is incorrect because it returns original base arguments for the child of the generic class instead of the target class itself. This uses obj.__dict__ to get the correct __orig_bases__ information.
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/inspect.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index b767b8adc..4482f2087 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -187,6 +187,21 @@ def getmro(obj: Any) -> Tuple[Type, ...]:
return tuple()
+def getorigbases(obj: Any) -> Optional[Tuple[Any, ...]]:
+ """Get __orig_bases__ from *obj* safely."""
+ if not inspect.isclass(obj):
+ return None
+
+ # Get __orig_bases__ from obj.__dict__ to avoid accessing the parent's __orig_bases__.
+ # refs: https://github.com/sphinx-doc/sphinx/issues/9607
+ __dict__ = safe_getattr(obj, '__dict__', {})
+ __orig_bases__ = __dict__.get('__orig_bases__')
+ if isinstance(__orig_bases__, tuple) and len(__orig_bases__) > 0:
+ return __orig_bases__
+ else:
+ return None
+
+
def getslots(obj: Any) -> Optional[Dict]:
"""Get __slots__ attribute of the class as dict.