diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2014-04-22 10:15:58 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2014-04-22 10:15:58 +0300 |
commit | 55f9360a1d2df64aaf019ac214daeda33e35c187 (patch) | |
tree | 5fec5656a1769788cb5d6f52915089b28c4694b7 | |
parent | 33f3dc90a8276a84173da8cfa6f0ab1100d7f482 (diff) | |
parent | 0420b574281c6efd8a43330f26f610dac5b7df69 (diff) | |
download | astroid-55f9360a1d2df64aaf019ac214daeda33e35c187.tar.gz |
Merged in PCManticore/astroid/ancestors (pull request #31)
Skip the same infered nodes as the base class in _is_metaclass. Closes issue #25
-rw-r--r-- | scoped_nodes.py | 2 | ||||
-rw-r--r-- | test/regrtest_data/recursion.py | 3 | ||||
-rw-r--r-- | test/unittest_regrtest.py | 21 |
3 files changed, 26 insertions, 0 deletions
diff --git a/scoped_nodes.py b/scoped_nodes.py index bce2ca1..185944b 100644 --- a/scoped_nodes.py +++ b/scoped_nodes.py @@ -681,6 +681,8 @@ def _is_metaclass(klass): return False if baseobj is YES: continue + if baseobj is klass: + continue if baseobj._type == 'metaclass': return True if _is_metaclass(baseobj): diff --git a/test/regrtest_data/recursion.py b/test/regrtest_data/recursion.py new file mode 100644 index 0000000..a34dad3 --- /dev/null +++ b/test/regrtest_data/recursion.py @@ -0,0 +1,3 @@ +""" For issue #25 """
+class Base(object):
+ pass
\ No newline at end of file diff --git a/test/unittest_regrtest.py b/test/unittest_regrtest.py index a171993..d4f937a 100644 --- a/test/unittest_regrtest.py +++ b/test/unittest_regrtest.py @@ -156,6 +156,27 @@ with open('a.txt') as stream, open('b.txt'): # context manager didn't use an assignment name. list(astroid.nodes_of_class(nodes.CallFunc))[-1].infered() + def test_recursion_regression_issue25(self): + builder = AstroidBuilder() + data = """ +import recursion as base + +_real_Base = base.Base + +class Derived(_real_Base): + pass + +def run(): + base.Base = Derived +""" + astroid = builder.string_build(data, __name__, __file__) + # Used to crash in _is_metaclass, due to wrong + # ancestors chain + classes = astroid.nodes_of_class(nodes.Class) + for klass in classes: + # triggers the _is_metaclass call + klass.type + class Whatever(object): a = property(lambda x: x, lambda x: x) |