summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2022-06-28 12:52:05 +0100
committerGitHub <noreply@github.com>2022-06-28 13:52:05 +0200
commit5c900c59d03f23f7329d6e68e114e4a277112916 (patch)
treebb81372a9bd9633bb9f7f7d2891cdc8af3ec41c9
parent530e370ff3d4d43e1969dcc821f65bf33a99f252 (diff)
downloadcython-5c900c59d03f23f7329d6e68e114e4a277112916.tar.gz
Fix tuple multiplication in MergedSequenceNode (GH-4864)
Fixes https://github.com/cython/cython/issues/4861
-rw-r--r--Cython/Compiler/ExprNodes.py2
-rw-r--r--tests/run/pep448_extended_unpacking.pyx18
2 files changed, 19 insertions, 1 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index 4a8ce5dca..9678647ad 100644
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -8482,7 +8482,7 @@ class MergedSequenceNode(ExprNode):
if type in (list_type, tuple_type) and args and args[0].is_sequence_constructor:
# construct a list directly from the first argument that we can then extend
if args[0].type is not list_type:
- args[0] = ListNode(args[0].pos, args=args[0].args, is_temp=True)
+ args[0] = ListNode(args[0].pos, args=args[0].args, is_temp=True, mult_factor=args[0].mult_factor)
ExprNode.__init__(self, pos, args=args, type=type)
def calculate_constant_result(self):
diff --git a/tests/run/pep448_extended_unpacking.pyx b/tests/run/pep448_extended_unpacking.pyx
index 08d39e526..4411d7e79 100644
--- a/tests/run/pep448_extended_unpacking.pyx
+++ b/tests/run/pep448_extended_unpacking.pyx
@@ -185,6 +185,24 @@ def unpack_list_literal_mult():
return [*([1, 2, *([4, 5] * 2)] * 3)]
+def unpack_list_tuple_mult():
+ """
+ >>> unpack_list_tuple_mult()
+ [1, 1]
+ """
+ return [*(1,) * 2]
+
+
+def unpack_list_tuple_bad_mult():
+ """
+ >>> unpack_list_tuple_bad_mult()
+ Traceback (most recent call last):
+ ...
+ TypeError: can't multiply sequence by non-int of type 'float'
+ """
+ return [*(1,) * 1.5]
+
+
@cython.test_fail_if_path_exists(
"//ListNode//ListNode",
"//MergedSequenceNode",