Commit 09ca6dab authored by Stefan Behnel's avatar Stefan Behnel

Exclude tuples with starred expressions from the %-formatting optimisation.

Closes GH-2939.
parent f4f6d1eb
...@@ -4322,6 +4322,9 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): ...@@ -4322,6 +4322,9 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
warning(pos, "Too few arguments for format placeholders", level=1) warning(pos, "Too few arguments for format placeholders", level=1)
can_be_optimised = False can_be_optimised = False
break break
if arg.is_starred:
can_be_optimised = False
break
if format_type in u'asrfdoxX': if format_type in u'asrfdoxX':
format_spec = s[1:] format_spec = s[1:]
if format_type in u'doxX' and u'.' in format_spec: if format_type in u'doxX' and u'.' in format_spec:
...@@ -4339,6 +4342,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): ...@@ -4339,6 +4342,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
else: else:
# keep it simple for now ... # keep it simple for now ...
can_be_optimised = False can_be_optimised = False
break
if not can_be_optimised: if not can_be_optimised:
# Print all warnings we can find before finally giving up here. # Print all warnings we can find before finally giving up here.
......
# mode: run
# tag: all_language_levels
cimport cython cimport cython
...@@ -144,6 +146,22 @@ def unpack_tuple_keep_originals(a, b, c): ...@@ -144,6 +146,22 @@ def unpack_tuple_keep_originals(a, b, c):
return (*a, *b, 2, *c) return (*a, *b, 2, *c)
def unpack_tuple_in_string_formatting(a, *args):
"""
>>> print(unpack_tuple_in_string_formatting(1, 2))
1 2
>>> print(unpack_tuple_in_string_formatting(1, 'x'))
1 'x'
>>> unpack_tuple_in_string_formatting(1) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...format...
>>> unpack_tuple_in_string_formatting(1, 2, 3) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...format...
"""
return "%s %r" % (a, *args)
#### lists #### lists
......
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