summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Martin <tim@asymptotic.co.uk>2020-10-07 18:44:48 +0100
committerTim Martin <tim@asymptotic.co.uk>2020-10-13 19:55:36 +0100
commit7f1d5134d89aab9b3e49030676637debfd731dbb (patch)
tree2bbc50a1bbc1896de3ff3fe4f6f46bcf78bad8be
parent1d14e985baf8847be60b81b7f6140e8606fd862a (diff)
downloadastroid-git-7f1d5134d89aab9b3e49030676637debfd731dbb.tar.gz
Fix incorrect MRO being calculated for scoped multiple inheritance
If a class inherits from two bases and the classes are expressed as a non-trivial expression such as qualified with a module name, classes after the first could not be inferred due to reusing the context object in _inferred_bases
-rw-r--r--ChangeLog4
-rw-r--r--astroid/scoped_nodes.py2
-rw-r--r--tests/unittest_scoped_nodes.py24
3 files changed, 29 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f4264935..86c6deee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -53,6 +53,10 @@ Release Date: TBA
* Fixed exception-chaining error messages.
+* Fix failure to infer base class type with multiple inheritance and qualified names
+
+ Fixes #843
+
What's New in astroid 2.4.3?
============================
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index 5c941966..a44e6282 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -2858,7 +2858,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, node_classes.Statement
for stmt in self.bases:
try:
- baseobj = next(stmt.infer(context=context))
+ baseobj = next(stmt.infer(context=context.clone()))
except exceptions.InferenceError:
continue
if isinstance(baseobj, bases.Instance):
diff --git a/tests/unittest_scoped_nodes.py b/tests/unittest_scoped_nodes.py
index c4597fa6..2606fd47 100644
--- a/tests/unittest_scoped_nodes.py
+++ b/tests/unittest_scoped_nodes.py
@@ -1417,6 +1417,30 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase):
],
)
+ def test_mro_with_attribute_classes(self):
+ cls = builder.extract_node(
+ """
+ class A:
+ pass
+ class B:
+ pass
+ scope = object()
+ scope.A = A
+ scope.B = B
+ class C(scope.A, scope.B):
+ pass
+ """
+ )
+ self.assertEqualMro(
+ cls,
+ [
+ "C",
+ "A",
+ "B",
+ "object"
+ ]
+ )
+
def test_generator_from_infer_call_result_parent(self):
func = builder.extract_node(
"""