diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2019-11-08 18:37:30 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-11-08 18:42:07 +0100 |
commit | 20a7ae5de32f716c8d7a4f5bbcd071bf353df4b2 (patch) | |
tree | 7191ec7830b976d76c5829203d624430389f2179 /astroid/protocols.py | |
parent | 501f73b53820a96df01a2438c5e91c3f3a1fe94a (diff) | |
download | astroid-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/protocols.py')
0 files changed, 0 insertions, 0 deletions