Commit 1faf51f0 authored by Arvind Natarajan's avatar Arvind Natarajan Committed by Stefan Behnel

Prevent in-list optimisation when the list contains starred expresssions (GH-4494)

Closes https://github.com/cython/cython/issues/3938
parent 20b3d5b5
......@@ -1347,6 +1347,10 @@ class FlattenInListTransform(Visitor.VisitorTransform, SkipDeclarations):
# note: lhs may have side effects
return node
if any([arg.is_starred for arg in args]):
# Starred arguments do not directly translate to comparisons or "in" tests.
return node
lhs = UtilNodes.ResultRefNode(node.operand1)
conds = []
......
......@@ -272,6 +272,24 @@ def unpack_list_keep_originals(a, b, c):
return [*a, *b, 2, *c]
def unpack_starred_arg_for_in_operator(x, l, m):
"""
>>> l = [1,2,3]
>>> m = [4,5,6]
>>> x = 1
>>> unpack_starred_arg_for_in_operator(x, l, m)
True
>>> x = 10
>>> unpack_starred_arg_for_in_operator(x, l, m)
False
>>> unpack_starred_arg_for_in_operator(x, l, [])
False
>>> unpack_starred_arg_for_in_operator(x, [], [])
False
"""
return x in [*l, *m]
###### sets
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment