summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-04-30 19:34:20 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-04-30 19:34:20 +0300
commit020a62ef90e6c9c5134c5f367f8f77695d25dc45 (patch)
tree561c2a456ade3b32c2262313519e369c8c664b2e
parent952bb8ee5575980e46fe11297fca636efa1822a2 (diff)
downloadastroid-020a62ef90e6c9c5134c5f367f8f77695d25dc45.tar.gz
Don't let ResolveError leak out from local_attr, when using .mro().
-rw-r--r--astroid/scoped_nodes.py7
-rw-r--r--astroid/tests/unittest_scoped_nodes.py7
2 files changed, 13 insertions, 1 deletions
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index 510961e..4fbcaea 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -1143,7 +1143,12 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
if self.newstyle and all(n.newstyle for n in self.ancestors(context)):
# Look up in the mro if we can. This will result in the
# attribute being looked up just as Python does it.
- ancestors = self.mro(context)[1:]
+ try:
+ ancestors = self.mro(context)[1:]
+ except ResolveError:
+ # Reraise it as NotFoundError, there's no reason
+ # for ResolveError to leak out.
+ six.raise_from(NotFoundError, ResolveError)
else:
ancestors = self.ancestors(context)
for astroid in ancestors:
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py
index 13af40c..db409cf 100644
--- a/astroid/tests/unittest_scoped_nodes.py
+++ b/astroid/tests/unittest_scoped_nodes.py
@@ -1319,6 +1319,13 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase):
""")
self.assertIsNone(cls.implicit_metaclass())
+ def test_local_attr_invalid_mro(self):
+ cls = test_utils.extract_node("""
+ class A(object, object):
+ pass
+ """)
+ self.assertRaises(NotFoundError, cls.local_attr, 'test')
+
if __name__ == '__main__':
unittest.main()