diff options
| author | hippo91 <guillaume.peillex@gmail.com> | 2018-12-02 16:20:06 +0100 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-01-23 09:09:22 +0100 |
| commit | 87b55a6ea6a421b4702dbc178a45165f20d1e775 (patch) | |
| tree | 18c75077ec735554381ecd88be576c3f18cec91a /astroid/node_classes.py | |
| parent | c54ca8e30d8cce8660ddac842c58b66de2733322 (diff) | |
| download | astroid-git-87b55a6ea6a421b4702dbc178a45165f20d1e775.tar.gz | |
Avoid statement deletion in the _filter_stmts method of the LookupMixin class for PartialFunction
In the case where the node is a PartialFunction and its name is the same as the current statement's name,
avoid the statement deletion.
The problem was that a call to a function that has been previously called vit a functools.partial was wrongly inferred.
The bug comes from the _filter_stmts method of the LookupMixin class. The deletion of the current statement should not be
made in the case where the node is an instance of the PartialFunction class and if the node's name is the same as the statement's name.
This change also extracts PartialFunction from brain_functools into astroid.objects so that we remove a circular import problem.
Close PyCQA/pylint#2588
Diffstat (limited to 'astroid/node_classes.py')
| -rw-r--r-- | astroid/node_classes.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/astroid/node_classes.py b/astroid/node_classes.py index 4e5f5612..0ab9be08 100644 --- a/astroid/node_classes.py +++ b/astroid/node_classes.py @@ -1217,8 +1217,16 @@ class LookupMixIn: # want to clear previous assignments if any (hence the test on # optional_assign) if not (optional_assign or are_exclusive(_stmts[pindex], node)): - del _stmt_parents[pindex] - del _stmts[pindex] + if ( + # In case of partial function node, if the statement is different + # from the origin function then it can be deleted otherwise it should + # remain to be able to correctly infer the call to origin function. + not node.is_function + or node.qname() != "PartialFunction" + or node.name != _stmts[pindex].name + ): + del _stmt_parents[pindex] + del _stmts[pindex] if isinstance(node, AssignName): if not optional_assign and stmt.parent is mystmt.parent: _stmts = [] |
