Skip to content

Fix + test for string format with %% and keys #1900

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
4 changes: 3 additions & 1 deletion mypy/checkstrformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def parse_conversion_specifiers(self, format: str) -> List[ConversionSpecifier]:
for parens_key, key, flags, width, precision, type in re.findall(regex, format):
if parens_key == '':
key = None
specifiers.append(ConversionSpecifier(key, flags, width, precision, type))
specifier = ConversionSpecifier(key, flags, width, precision, type)
if specifier.type != '%' or specifier.has_star():
specifiers.append(specifier)
return specifiers

def analyze_conversion_specifiers(self, specifiers: List[ConversionSpecifier],
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 @@ -989,6 +989,8 @@ a = None # type: Any
'%()d' % {'': 2}
'%(a)d' % {'a': 1, 'b': 2, 'c': 3}
'%(q)d' % {'a': 1, 'b': 2, 'c': 3} # E: Key 'q' not found in mapping
'%(a)d %%' % {'a': 1}

[builtins fixtures/dict.py]

[case testStringInterpolationMappingDictTypes]
Expand Down