summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--astroid/node_classes.py3
-rw-r--r--tests/unittest_regrtest.py19
3 files changed, 24 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index cdabb7f1..83c09682 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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()