Skip to content

Commit

Permalink
Fix a crash involving two starred expressions inside a call (#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored and Pierre-Sassoulas committed May 2, 2022
1 parent be9235c commit 2e383f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Release date: TBA

* Fix ``col_offset`` attribute for nodes involving ``with`` on ``PyPy``.

* Fixed a crash involving two starred expressions: one inside a comprehension,
both inside a call.

Refs PyCQA/pylint#6372

* Made ``FunctionDef.implicit_parameters`` return 1 for methods by making
``FunctionDef.is_bound`` return ``True``, as it does for class methods.

Expand Down
3 changes: 3 additions & 0 deletions astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@ def _determine_starred_iteration_lookups(starred, target, lookups):
if isinstance(stmt, nodes.Assign):
value = stmt.value
lhs = stmt.targets[0]
if not isinstance(lhs, nodes.BaseContainer):
yield util.Uninferable
return

if sum(1 for _ in lhs.nodes_of_class(nodes.Starred)) > 1:
raise InferenceError(
Expand Down
11 changes: 11 additions & 0 deletions tests/unittest_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ def test(arg):
"a, (*b, c), d = (1, (2, 3, 4), 5) #@", Uninferable
)

def test_assigned_stmts_starred_inside_call(self) -> None:
"""Regression test for https://github.com/PyCQA/pylint/issues/6372"""
code = "string_twos = ''.join(str(*y) for _, *y in [[1, 2], [1, 2]]) #@"
stmt = extract_node(code)
starred = next(stmt.nodes_of_class(nodes.Starred))
starred_stmts = starred.assigned_stmts()
self.assertIs(next(starred_stmts), Uninferable)
# Generator exhausted after one call
with self.assertRaises(StopIteration):
next(starred_stmts)

def test_assign_stmts_starred_fails(self) -> None:
# Too many starred
self._helper_starred_inference_error("a, *b, *c = (1, 2, 3) #@")
Expand Down

0 comments on commit 2e383f3

Please sign in to comment.