Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e55f105
Temporary debug statement + first correction of the bug 2588 by avoid…
hippo91 Dec 2, 2018
16eb616
Merge remote-tracking branch 'origin/master' into bug_pylint_2588
hippo91 Dec 8, 2018
1f7dd68
Merge branch 'master' into bug_pylint_2588_bis
hippo91 Dec 15, 2018
f847792
Fix the pylint's bug 2588 by avoiding statement deletion in the _filt…
hippo91 Dec 15, 2018
7400abb
Reactivation of the unittests dedicated to brain_functools. Add of a …
hippo91 Dec 15, 2018
c5da3d2
Suppress a debugger statement
hippo91 Dec 15, 2018
151217c
Add of ChangeLog entry
hippo91 Dec 15, 2018
e4e4a49
Merge branch 'master' into bug_pylint_2588_bis
hippo91 Dec 21, 2018
67a32eb
Removing unittest.TestCase inheritance for TestFunctoolsPartial
hippo91 Dec 22, 2018
362832f
Extracting the class PartialFunction from brain_functools and inserti…
hippo91 Dec 22, 2018
66c413e
Reformating with black
hippo91 Dec 22, 2018
f6cbb1a
Finalzing the test case
hippo91 Dec 22, 2018
b3fa94a
Just breakpoint to debug and mark the origin of the problem
hippo91 Dec 22, 2018
b85b6da
Revert "Just breakpoint to debug and mark the origin of the problem"
hippo91 Dec 22, 2018
b1937b9
Merge branch 'master' of https://github.com/PyCQA/astroid
hippo91 Jan 3, 2019
f13c51b
Merge branch 'master' into bug_pylint_2588_bis
hippo91 Jan 3, 2019
e1c899a
Correcting formatting according to black 18.6b4
hippo91 Jan 3, 2019
fd3cdad
Merge branch 'master' of https://github.com/PyCQA/astroid
hippo91 Jan 20, 2019
9c17b23
Merge branch 'master' into bug_pylint_2588_bis
hippo91 Jan 20, 2019
99eabe2
Merge branch 'master' of https://github.com/PyCQA/astroid
hippo91 Jan 21, 2019
bbc41b0
Merge branch 'master' into bug_pylint_2588_bis
hippo91 Jan 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ What's New in astroid 2.2.0?
============================
Release Date: TBA

* Fix a bug where a call to a function that has been previously called via
functools.partial was wrongly inferred

Close PyCQA/pylint#2588

* Fix a bug where an Attribute used as a base class was triggering a crash

Close #626
Expand Down
1 change: 1 addition & 0 deletions astroid/brain/brain_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class PartialFunction(astroid.FunctionDef):

filled_positionals = len(call.positional_arguments[1:])
filled_keywords = list(call.keyword_arguments)
is_partial_function = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hippo91 I wonder if we can extract PartialFunction somehow from this module. We can use astroid.objects for it, and if we need to figure out if a function is partial or not, we can implement the name property and qname function, just like we do for Super, FrozenSet and friends. And instead of checking if is_partial_function is given, we only look for .name against a predefined list of elements for which to apply the condition in the mixin. Do you think that's worth it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PCManticore it looks interesting.
I work on it.


def infer_call_result(self, caller=None, context=None):
nonlocal call
Expand Down
5 changes: 3 additions & 2 deletions astroid/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,9 @@ def _filter_stmts(self, stmts, frame, offset):
# 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 not hasattr(node, 'is_partial_function') or node.name != _stmts[pindex].name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for the second check, can you add a comment for that?

del _stmt_parents[pindex]
del _stmts[pindex]
if isinstance(node, AssignName):
if not optional_assign and stmt.parent is mystmt.parent:
_stmts = []
Expand Down
10 changes: 6 additions & 4 deletions astroid/tests/unittest_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ def test_infer_dict_from_keys():
assert sorted(actual_values) == ["a", "b", "c"]


class TestFunctoolsPartial:
class TestFunctoolsPartial(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hippo91 It's not required to add unittest.TestCase here because we use pytest and it is able to find these tests accordingly.

def test_invalid_functools_partial_calls(self):
ast_nodes = astroid.extract_node(
"""
Expand Down Expand Up @@ -1741,13 +1741,15 @@ def other_test(a, b, *, c=1):
partial(other_test, c=4)(1, 3) #@
partial(other_test, 4, c=4)(4) #@
partial(other_test, 4, c=4)(b=5) #@
test(1, 2) #@
partial(other_test, 1, 2)(c=3) #@
"""
)
expected_values = [4, 7, 7, 3, 12, 16, 32, 36]
expected_values = [4, 7, 7, 3, 12, 16, 32, 36, 3, 9]
for node, expected_value in zip(ast_nodes, expected_values):
inferred = next(node.infer())
assert isinstance(inferred, astroid.Const)
assert inferred.value == expected_value
self.assertIsInstance(inferred, astroid.Const)
self.assertEqual(inferred.value, expected_value)


if __name__ == "__main__":
Expand Down