From 3f56cde2186ce77dbec7e3c87533034983fb19f4 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Thu, 1 Sep 2016 12:03:24 -0700 Subject: [PATCH] Accept ' ' as a valid format specifier name Fix #2058. --- mypy/checkstrformat.py | 2 +- test-data/unit/check-expressions.test | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mypy/checkstrformat.py b/mypy/checkstrformat.py index 23ec912ecf80..678f51a14001 100644 --- a/mypy/checkstrformat.py +++ b/mypy/checkstrformat.py @@ -70,7 +70,7 @@ def check_str_interpolation(self, str: StrExpr, replacements: Node) -> Type: return self.named_type('builtins.str') def parse_conversion_specifiers(self, format: str) -> List[ConversionSpecifier]: - key_regex = r'(\((\w*)\))?' # (optional) parenthesised sequence of characters + key_regex = r'(\(([\w ]*)\))?' # (optional) parenthesised sequence of characters flags_regex = r'([#0\-+ ]*)' # (optional) sequence of flags width_regex = r'(\*|[1-9][0-9]*)?' # (optional) minimum field width (* or numbers) precision_regex = r'(?:\.(\*|[0-9]+)?)?' # (optional) . followed by * of numbers diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index c28b2fff2634..2ec8f8b9641d 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -1108,6 +1108,8 @@ di = None # type: Dict[int, int] main:3: error: Incompatible types in string interpolation (expression has type "str", placeholder has type "Union[int, float]") main:4: error: Incompatible types in string interpolation (expression has type "str", placeholder has type "Union[int, float]") +[case testStringInterpolationSpaceKey] +'%( )s' % {' ': 'foo'} -- Lambdas -- -------