summaryrefslogtreecommitdiff
path: root/checkers/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'checkers/utils.py')
-rw-r--r--checkers/utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/checkers/utils.py b/checkers/utils.py
index 000aee7..b3ba51b 100644
--- a/checkers/utils.py
+++ b/checkers/utils.py
@@ -462,3 +462,22 @@ def is_import_error(handler):
return True
except astroid.InferenceError:
continue
+
+def has_known_bases(klass):
+ """Returns true if all base classes of a class could be inferred."""
+ try:
+ return klass._all_bases_known
+ except AttributeError:
+ pass
+ try:
+ for base in klass.bases:
+ result = base.infer().next()
+ # TODO: check for A->B->A->B pattern in class structure too?
+ if not isinstance(result, astroid.Class) or result is klass or not has_known_bases(result):
+ klass._all_bases_known = False
+ return False
+ except astroid.InferenceError:
+ klass._all_bases_known = False
+ return False
+ klass._all_bases_known = True
+ return True