diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2020-06-16 09:12:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-16 09:12:43 +0200 |
commit | 5e9519dfb1364a69abeca44f80480237526d67e3 (patch) | |
tree | 0ed91652f9f41c46f94d9e4f7f7e520bd60f65c3 | |
parent | 03e2986682b429d1ffb1f017e34537ab4c8e2ac5 (diff) | |
download | astroid-git-2.4.tar.gz |
Fix a crash caused by a lookup of a monkey-patched method (#803)2.4
Close PyCQA/pylint#3686
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | astroid/node_classes.py | 3 | ||||
-rw-r--r-- | tests/unittest_regrtest.py | 19 |
3 files changed, 24 insertions, 2 deletions
@@ -6,6 +6,10 @@ What's New in astroid 2.4.3? ============================ Release Date: TBA +* Fix a crash caused by a lookup of a monkey-patched method + + Close PyCQA/pylint#3686 + What's New in astroid 2.4.2? ============================ diff --git a/astroid/node_classes.py b/astroid/node_classes.py index 621dc5f2..dfe85b04 100644 --- a/astroid/node_classes.py +++ b/astroid/node_classes.py @@ -1149,10 +1149,9 @@ class LookupMixIn: _stmts = [] _stmt_parents = [] statements = self._get_filtered_node_statements(stmts) - for node, stmt in statements: # line filtering is on and we have reached our location, break - if stmt.fromlineno > mylineno > 0: + if stmt.fromlineno and stmt.fromlineno > mylineno > 0: break # Ignore decorators with the same name as the # decorated function diff --git a/tests/unittest_regrtest.py b/tests/unittest_regrtest.py index 7171941b..17668edd 100644 --- a/tests/unittest_regrtest.py +++ b/tests/unittest_regrtest.py @@ -324,5 +324,24 @@ class Whatever: a = property(lambda x: x, lambda x: x) +def test_ancestor_looking_up_redefined_function(): + code = """ + class Foo: + def _format(self): + pass + + def format(self): + self.format = self._format + self.format() + Foo + """ + node = extract_node(code) + inferred = next(node.infer()) + ancestor = next(inferred.ancestors()) + _, found = ancestor.lookup("format") + assert len(found) == 1 + assert isinstance(found[0], nodes.FunctionDef) + + if __name__ == "__main__": unittest.main() |