summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2022-04-30 12:21:05 -0400
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-05-02 13:56:00 +0200
commit2e383f3da69c71925904b15ad2f97e247cda419f (patch)
tree6a0ae55eac4c6a15cc40d5e0578dc56709cbeb58
parentbe9235ce3eaf78d0ffd285c595bfa8d699a3a895 (diff)
downloadastroid-git-2e383f3da69c71925904b15ad2f97e247cda419f.tar.gz
Fix a crash involving two starred expressions inside a call (#1535)
-rw-r--r--ChangeLog5
-rw-r--r--astroid/protocols.py3
-rw-r--r--tests/unittest_protocols.py11
3 files changed, 19 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 2dd63c70..c69642f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/astroid/protocols.py b/astroid/protocols.py
index 1ec1121b..f1fcec0d 100644
--- a/astroid/protocols.py
+++ b/astroid/protocols.py
@@ -690,6 +690,9 @@ def starred_assigned_stmts(
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(
diff --git a/tests/unittest_protocols.py b/tests/unittest_protocols.py
index 7c3abb8d..59f82c39 100644
--- a/tests/unittest_protocols.py
+++ b/tests/unittest_protocols.py
@@ -125,6 +125,17 @@ class ProtocolTests(unittest.TestCase):
"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) #@")