Commit 5c900c59 authored by da-woods's avatar da-woods Committed by GitHub

Fix tuple multiplication in MergedSequenceNode (GH-4864)

Fixes https://github.com/cython/cython/issues/4861
parent 530e370f
...@@ -8482,7 +8482,7 @@ class MergedSequenceNode(ExprNode): ...@@ -8482,7 +8482,7 @@ class MergedSequenceNode(ExprNode):
if type in (list_type, tuple_type) and args and args[0].is_sequence_constructor: 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 # construct a list directly from the first argument that we can then extend
if args[0].type is not list_type: 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) ExprNode.__init__(self, pos, args=args, type=type)
def calculate_constant_result(self): def calculate_constant_result(self):
......
...@@ -185,6 +185,24 @@ def unpack_list_literal_mult(): ...@@ -185,6 +185,24 @@ def unpack_list_literal_mult():
return [*([1, 2, *([4, 5] * 2)] * 3)] 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( @cython.test_fail_if_path_exists(
"//ListNode//ListNode", "//ListNode//ListNode",
"//MergedSequenceNode", "//MergedSequenceNode",
......
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