-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
bytes formatting incorrect in python 3 #2070
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
Oooh, good catch! I suspect the % checking code for bytes was too hastily adapted from the same for strings. There are many things wrong there: the checker always assumes the full formatting language used for str, while bytes have a separate (weaker) language. It always returns |
(Also, though not affecting mypy's behavior, typeshed has no |
@buckbaskin If you want to tackle this that's great! IIRC it should be a fairly simple refactoring and doing this will get you up to speed with how to run the tests. (Hint: |
It looks like the type checking code for bytes is just to use the string version (see checkexpr.py). The lines effectively check to see if it either matches Would the correct way to fix this be to create a new checker for Bytes? Or possibly to add a method to what is now StringFormatterChecker that checks bytes instead? |
The quick and dirty fix would be to just change the return type to be the same as the arg type. But the bytes % operator supports a smaller mini-language, so technically StringFormatterChecker should grow another method to handle that. Or maybe a subclass? The main thing that ought to change seems to be conversion_type(). But I'll settle for the quick and dirty fix as a first installment! |
In the pull request, I added a separate method that handles BytesExpr. I don't think that the type checking for what can be interpolated into a |
Unit tests for % formatting are in test-data/unit/check-expressions.test
under "String interpolation" -- please do add some tests for bytes there
too! (And unicode, you can do that in tests whose name ends in `_python2`.)
|
The following runs properly:
However mypy complains:
The text was updated successfully, but these errors were encountered: