Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/checkstrformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not "anything except parentheses"? What does Python itself implement or document?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation doesn't specifically discuss this, but I tested all ASCII characters and everything except parentheses worked. I'll fix this up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to just change it. >_>
7c76609

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
Expand Down
2 changes: 2 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
-- -------
Expand Down