Skip to content

Commit e1774a7

Browse files
gvanrossumJukkaL
authored andcommitted
Be aware of StarExpr in tuple when checking string conversions (#2866)
Fixes #2794.
1 parent 16a0f81 commit e1774a7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

mypy/checkstrformat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Type, AnyType, TupleType, Instance, UnionType
99
)
1010
from mypy.nodes import (
11-
StrExpr, BytesExpr, UnicodeExpr, TupleExpr, DictExpr, Context, Expression
11+
StrExpr, BytesExpr, UnicodeExpr, TupleExpr, DictExpr, Context, Expression, StarExpr
1212
)
1313
if False:
1414
# break import cycle only needed for mypy
@@ -140,7 +140,8 @@ def check_simple_str_interpolation(self, specifiers: List[ConversionSpecifier],
140140
check_type(rhs_type.items[0])
141141
else:
142142
check_node(replacements)
143-
elif isinstance(replacements, TupleExpr):
143+
elif (isinstance(replacements, TupleExpr)
144+
and not any(isinstance(item, StarExpr) for item in replacements.items)):
144145
for checks, rep_node in zip(checkers, replacements.items):
145146
check_node, check_type = checks
146147
check_node(rep_node)

test-data/unit/check-expressions.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,10 @@ def foo(a: bytes, b: bytes):
11491149
b'%s:%s' % (a, b)
11501150
foo(b'a', b'b') == b'a:b'
11511151

1152+
[case testStringInterpolationStarArgs]
1153+
x = (1, 2)
1154+
"%d%d" % (*x,)
1155+
11521156
[case testBytePercentInterpolationSupported]
11531157
b'%s' % (b'xyz',)
11541158
b'%(name)s' % {'name': 'jane'}

0 commit comments

Comments
 (0)