Skip to content

Commit 66df764

Browse files
committed
Fix a crash caused by a lookup of a monkey-patched method (#803)
Close pylint-dev/pylint#3686
1 parent 1cf413f commit 66df764

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ Release Date: TBA
2424
Close PyCQA/pylint#3583
2525

2626

27+
What's New in astroid 2.4.3?
28+
============================
29+
Release Date: TBA
30+
31+
* Fix a crash caused by a lookup of a monkey-patched method
32+
33+
Close PyCQA/pylint#3686
34+
35+
2736
What's New in astroid 2.4.2?
2837
============================
2938
Release Date: 2020-06-08

astroid/node_classes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,10 +1149,9 @@ def _filter_stmts(self, stmts, frame, offset):
11491149
_stmts = []
11501150
_stmt_parents = []
11511151
statements = self._get_filtered_node_statements(stmts)
1152-
11531152
for node, stmt in statements:
11541153
# line filtering is on and we have reached our location, break
1155-
if stmt.fromlineno > mylineno > 0:
1154+
if stmt.fromlineno and stmt.fromlineno > mylineno > 0:
11561155
break
11571156
# Ignore decorators with the same name as the
11581157
# decorated function

tests/unittest_regrtest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,5 +324,24 @@ class Whatever:
324324
a = property(lambda x: x, lambda x: x)
325325

326326

327+
def test_ancestor_looking_up_redefined_function():
328+
code = """
329+
class Foo:
330+
def _format(self):
331+
pass
332+
333+
def format(self):
334+
self.format = self._format
335+
self.format()
336+
Foo
337+
"""
338+
node = extract_node(code)
339+
inferred = next(node.infer())
340+
ancestor = next(inferred.ancestors())
341+
_, found = ancestor.lookup("format")
342+
assert len(found) == 1
343+
assert isinstance(found[0], nodes.FunctionDef)
344+
345+
327346
if __name__ == "__main__":
328347
unittest.main()

0 commit comments

Comments
 (0)