|
184 | 184 | str_ssize_t_size_op, |
185 | 185 | unicode_compare, |
186 | 186 | ) |
187 | | -from mypyc.primitives.tuple_ops import list_tuple_op, new_tuple_op, new_tuple_with_length_op |
| 187 | +from mypyc.primitives.tuple_ops import ( |
| 188 | + list_tuple_op, |
| 189 | + new_tuple_op, |
| 190 | + new_tuple_with_length_op, |
| 191 | + sequence_tuple_op, |
| 192 | +) |
188 | 193 | from mypyc.rt_subtype import is_runtime_subtype |
189 | 194 | from mypyc.sametype import is_same_type |
190 | 195 | from mypyc.subtype import is_subtype |
@@ -789,16 +794,25 @@ def _construct_varargs( |
789 | 794 | for value, kind, name in args: |
790 | 795 | if kind == ARG_STAR: |
791 | 796 | if star_result is None: |
792 | | - # fast path if star expr is a tuple: |
793 | | - # we can pass the immutable tuple straight into the function call. |
794 | | - if is_tuple_rprimitive(value.type): |
795 | | - if len(args) == 1: |
796 | | - # fn(*args) |
797 | | - return value, self._create_dict([], [], line) |
798 | | - elif len(args) == 2 and args[1][1] == ARG_STAR2: |
799 | | - # fn(*args, **kwargs) |
| 797 | + # star args fastpath |
| 798 | + if len(args) == 1: |
| 799 | + # fn(*args) |
| 800 | + if is_list_rprimitive(value.type): |
| 801 | + value = self.primitive_op(list_tuple_op, [value], line) |
| 802 | + elif not is_tuple_rprimitive(value.type) and not isinstance( |
| 803 | + value.type, RTuple |
| 804 | + ): |
| 805 | + value = self.primitive_op(sequence_tuple_op, [value], line) |
| 806 | + return value, self._create_dict([], [], line) |
| 807 | + elif len(args) == 2 and args[1][1] == ARG_STAR2: |
| 808 | + # fn(*args, **kwargs) |
| 809 | + if is_tuple_rprimitive(value.type) or isinstance(value.type, RTuple): |
800 | 810 | star_result = value |
801 | | - continue |
| 811 | + elif is_list_rprimitive(value.type): |
| 812 | + star_result = self.primitive_op(list_tuple_op, [value], line) |
| 813 | + else: |
| 814 | + star_result = self.primitive_op(sequence_tuple_op, [value], line) |
| 815 | + continue |
802 | 816 | # elif ...: TODO extend this to optimize fn(*args, k=1, **kwargs) case |
803 | 817 | # TODO optimize this case using the length utils - currently in review |
804 | 818 | star_result = self.new_list_op(star_values, line) |
|
0 commit comments