summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-11-08 18:37:30 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2019-11-08 18:42:07 +0100
commit20a7ae5de32f716c8d7a4f5bbcd071bf353df4b2 (patch)
tree7191ec7830b976d76c5829203d624430389f2179 /astroid
parent501f73b53820a96df01a2438c5e91c3f3a1fe94a (diff)
downloadastroid-git-20a7ae5de32f716c8d7a4f5bbcd071bf353df4b2.tar.gz
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 PyCQA/pylint#3225
Diffstat (limited to 'astroid')
-rw-r--r--astroid/interpreter/objectmodel.py1
1 files changed, 0 insertions, 1 deletions
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index 5e488d9d..f37ae973 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -322,7 +322,6 @@ class FunctionModel(ObjectModel):
doc=func.doc,
lineno=func.lineno,
col_offset=func.col_offset,
- parent=cls,
)
# pylint: disable=no-member
new_func.postinit(func.args, func.body, func.decorators, func.returns)