Skip to content

Commit 519ae7a

Browse files
Fix a crash involving two starred expressions inside a call (#1535)
1 parent 9968101 commit 519ae7a

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ Release date: TBA
2323

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

26+
* Fixed a crash involving two starred expressions: one inside a comprehension,
27+
both inside a call.
28+
29+
Refs PyCQA/pylint#6372
30+
2631
* Made ``FunctionDef.implicit_parameters`` return 1 for methods by making
2732
``FunctionDef.is_bound`` return ``True``, as it does for class methods.
2833

astroid/protocols.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,9 @@ def _determine_starred_iteration_lookups(starred, target, lookups):
690690
if isinstance(stmt, nodes.Assign):
691691
value = stmt.value
692692
lhs = stmt.targets[0]
693+
if not isinstance(lhs, nodes.BaseContainer):
694+
yield util.Uninferable
695+
return
693696

694697
if sum(1 for _ in lhs.nodes_of_class(nodes.Starred)) > 1:
695698
raise InferenceError(

tests/unittest_protocols.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ def test(arg):
125125
"a, (*b, c), d = (1, (2, 3, 4), 5) #@", Uninferable
126126
)
127127

128+
def test_assigned_stmts_starred_inside_call(self) -> None:
129+
"""Regression test for https://github.com/PyCQA/pylint/issues/6372"""
130+
code = "string_twos = ''.join(str(*y) for _, *y in [[1, 2], [1, 2]]) #@"
131+
stmt = extract_node(code)
132+
starred = next(stmt.nodes_of_class(nodes.Starred))
133+
starred_stmts = starred.assigned_stmts()
134+
self.assertIs(next(starred_stmts), Uninferable)
135+
# Generator exhausted after one call
136+
with self.assertRaises(StopIteration):
137+
next(starred_stmts)
138+
128139
def test_assign_stmts_starred_fails(self) -> None:
129140
# Too many starred
130141
self._helper_starred_inference_error("a, *b, *c = (1, 2, 3) #@")

0 commit comments

Comments
 (0)