Skip to content

Incorrect check on string interpolation #1717

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
dmoisset opened this issue Jun 16, 2016 · 4 comments · Fixed by #1908
Closed

Incorrect check on string interpolation #1717

dmoisset opened this issue Jun 16, 2016 · 4 comments · Fixed by #1908
Labels
bug mypy got something wrong

Comments

@dmoisset
Copy link
Contributor

When sending this type-correct code

d = {"greeting": "hello", "count": 10}
print("%(greeting)s World. %(count)d%% tests failing" % d)

through mypy, I get the following:

error: String interpolation mixes specifier with and without mapping keys

Which should be accepted; the only interpolator I'm using withot keys is "%%" which is just an escape and can not cause problems

@gvanrossum gvanrossum added bug mypy got something wrong difficulty/easy labels Jun 23, 2016
@gvanrossum gvanrossum added this to the 0.5 milestone Jun 23, 2016
@ddfisher
Copy link
Collaborator

This does look like it's related to the %%. Here's a slightly reduced repro: "%(foo)s %%" % {"foo": "foo"}

@fabianhjr
Copy link
Contributor

fabianhjr commented Jul 19, 2016

Ok, so basically this has to do with a regex in parse_conversion_specifiers(self, format: str) -> List[ConversionSpecifier]: in checkstrformat.py.

Overall, I have been researching and %% should be an escape character, so this is what I think should be done:

Prepend (?:%%)| to the regex to catch the escape.

EDIT: Testing this change returns empty matches; Should be easier to filter out.

@gvanrossum
Copy link
Member

Wanna add tests and submit a PR?

On Monday, July 18, 2016, Fabian Heredia Montiel [email protected]
wrote:

Ok, so basically this has to do with a regex in parse_conversion_specifiers(self,
format: str) -> List[ConversionSpecifier]: in checkstrformat.py.

Overall, I have been researching and %% should be an escape character, so
this is what I think should be done:

Prepend (?:%%)| to the regex to catch the escape.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#1717 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACwrMkqNtyFSZnsnlj5nUqlikDFugClBks5qXEgsgaJpZM4I3jvd
.

--Guido (mobile)

@fabianhjr
Copy link
Contributor

Working on it; if I get it to pass locally I will open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
4 participants