Skip to content

Accept ' ' as a valid format specifier name #2079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2016
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