Skip to content

Commit 74b59d4

Browse files
ddfishergvanrossum
authored andcommitted
Accept ' ' as a valid format specifier name (#2079)
Fix #2058.
1 parent 582ab70 commit 74b59d4

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

mypy/checkstrformat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def check_str_interpolation(self, str: StrExpr, replacements: Node) -> Type:
7070
return self.named_type('builtins.str')
7171

7272
def parse_conversion_specifiers(self, format: str) -> List[ConversionSpecifier]:
73-
key_regex = r'(\((\w*)\))?' # (optional) parenthesised sequence of characters
73+
key_regex = r'(\(([\w ]*)\))?' # (optional) parenthesised sequence of characters
7474
flags_regex = r'([#0\-+ ]*)' # (optional) sequence of flags
7575
width_regex = r'(\*|[1-9][0-9]*)?' # (optional) minimum field width (* or numbers)
7676
precision_regex = r'(?:\.(\*|[0-9]+)?)?' # (optional) . followed by * of numbers

test-data/unit/check-expressions.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,8 @@ di = None # type: Dict[int, int]
11081108
main:3: error: Incompatible types in string interpolation (expression has type "str", placeholder has type "Union[int, float]")
11091109
main:4: error: Incompatible types in string interpolation (expression has type "str", placeholder has type "Union[int, float]")
11101110

1111+
[case testStringInterpolationSpaceKey]
1112+
'%( )s' % {' ': 'foo'}
11111113

11121114
-- Lambdas
11131115
-- -------

0 commit comments

Comments
 (0)