-
-
Notifications
You must be signed in to change notification settings - Fork 3k
'%d' % SupportsInt fails #7114
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
Comments
This should be a pretty straightforward fix to |
@msullivan Where do I have to add it? I can make a PR! |
It looks like fixing this involves modifying the |
@Patil2099 it looks like Ivan has fixed this as part of a broader overhaul of string formatting, though. Sorry! |
Fixes #1444 Fixes #2639 Fixes #7114 This PR does three related things: * Fixes some corner cases in `%` formatting * Tightens `bytes` vs `str` interactions (including those that are technically not errors) * Adds type checking for `str.format()` calls This also fixes few issues discovered by this PR during testing (notably a bug in f-string transformation), and adds/extends a bunch of docstring and comments to existing code. The implementation is mostly straightforward, there are few hacky things, but IMO nothing unreasonable. Here are few comments: * It was hard to keep the approach to `str.format()` calls purely regexp-based (as for `%` formatting), mostly because the former can be both nested and repeated (And we must support nested formatting because this is how we support f-strings). CPython itself uses a custom parser but it is huge, so I decided to have a mixed approach. This way we can keep code simple while still maintaining practically one-to-one compatibility with runtime behavior (the error messages are sometimes different however). * This causes few hundreds of errors internally, I am not sure what to do with these. Most popular ones are: - Unicode upcast (`'%s' % u'...'` results in `unicode`, not `str`, on Python 2) - Using `'%s' % some_bytes` and/or `'{:s}'.format(some_bytes)` on Python 3 - Unused arguments in `str.format()` call (probably because at runtime they are silently ignored) * I added new error code for string interpolation/formatting and used it everywhere in old and new code. Potentially we might split out the `str` vs `bytes` errors into a separate error code, because technically they are not type errors, just suspicious/dangerous code.
Uh oh!
There was an error while loading. Please reload this page.
results in
While in runtime it provides a reasonable
'5'
.The text was updated successfully, but these errors were encountered: