Skip to content

Fixes #1717 by skiping the %% literal in parse_conversion_specifiers. #1905

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 5 additions & 1 deletion mypy/checkstrformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ def parse_conversion_specifiers(self, format: str) -> List[ConversionSpecifier]:
regex = ('%' + key_regex + flags_regex + width_regex +
precision_regex + length_mod_regex + type_regex)
specifiers = [] # type: List[ConversionSpecifier]
for parens_key, key, flags, width, precision, type in re.findall(regex, format):
for result in re.findall(regex, format):
# The following test gets rid of the `%%` literal.
if result == ('', '', '', '', '', '%'):
continue
parens_key, key, flags, width, precision, type = result
if parens_key == '':
key = None
specifiers.append(ConversionSpecifier(key, flags, width, precision, type))
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ a = None # type: Any
'%3% %d' % 1
'%*%' % 1
'%*% %d' % 1 # E: Not enough arguments for format string
'%(a)d %%' % {'a': 1}
[builtins fixtures/primitives.py]

[case testStringInterpolationC]
Expand Down