From ffcedb0b60dbaa16eca453a5d3a23aa575ba284c Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 8 Feb 2017 10:39:37 -0800 Subject: [PATCH 1/2] Be aware of StarExpr in tuple when checking string conversions --- mypy/checkstrformat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mypy/checkstrformat.py b/mypy/checkstrformat.py index dd53bb01b966..9c5a8f925849 100644 --- a/mypy/checkstrformat.py +++ b/mypy/checkstrformat.py @@ -8,7 +8,7 @@ Type, AnyType, TupleType, Instance, UnionType ) from mypy.nodes import ( - StrExpr, BytesExpr, UnicodeExpr, TupleExpr, DictExpr, Context, Expression + StrExpr, BytesExpr, UnicodeExpr, TupleExpr, DictExpr, Context, Expression, StarExpr ) if False: # break import cycle only needed for mypy @@ -140,7 +140,8 @@ def check_simple_str_interpolation(self, specifiers: List[ConversionSpecifier], check_type(rhs_type.items[0]) else: check_node(replacements) - elif isinstance(replacements, TupleExpr): + elif (isinstance(replacements, TupleExpr) + and not any(isinstance(item, StarExpr) for item in replacements.items)): for checks, rep_node in zip(checkers, replacements.items): check_node, check_type = checks check_node(rep_node) From c4cb3783e7c497d6ad1748f9b2a35e8239ee51fa Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 25 Feb 2017 17:13:01 -0800 Subject: [PATCH 2/2] Add test case --- test-data/unit/check-expressions.test | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 8d221748023e..d3e3c133920e 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -1149,6 +1149,10 @@ def foo(a: bytes, b: bytes): b'%s:%s' % (a, b) foo(b'a', b'b') == b'a:b' +[case testStringInterpolationStarArgs] +x = (1, 2) +"%d%d" % (*x,) + [case testBytePercentInterpolationSupported] b'%s' % (b'xyz',) b'%(name)s' % {'name': 'jane'}