Skip to content

Commit 20a7ae5

Browse files
committed
Don't set a parent for descriptor bound methods created on __get__ access
This is a very tricky bug and requires particular circumstances to reproduce. For `f.__get__` we have a custom binding interface that generates bound methods on the fly whenever we encounter an `f.__get__(None, ...)` call. On function creation, we set the name of the function as a variable in the frame of the function's parent. e.g. for the following, we'll set `variable` as a name in the function's locals: class A: ... def variable(self): # variable will be part of A.locals pass Now the bug that this commit solves requires a `__get__()` binding such as the one mentioned as well as passing an object's dunder attribute to `__get__`, such as `object.__eq__`. The result is that the `None` that was passed in `f.__get__` will have as a frame the function where the descriptor binding method was called, which will result in `__eq__` to be marked as a variable of the function that was called, which is completely wrong. As a solution we don't set any parent for descriptor bound methods, which are created on the fly and thus the parent might be wrong altogether. Close pylint-dev/pylint#3225
1 parent 501f73b commit 20a7ae5

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

astroid/interpreter/objectmodel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ def infer_call_result(self, caller, context=None):
322322
doc=func.doc,
323323
lineno=func.lineno,
324324
col_offset=func.col_offset,
325-
parent=cls,
326325
)
327326
# pylint: disable=no-member
328327
new_func.postinit(func.args, func.body, func.decorators, func.returns)

0 commit comments

Comments
 (0)