-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
**kwargs
should be of type Dict[Union[str, unicode], Any]
in Python 2
#1954
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
Oh, I think the type of **kwargs may have to be made Dict[unicode, ...]
instead of Dict[str, ...]. There's probably somewhere in mypy where it does
that.
|
Thanks @gvanrossum! Out of curiosity, why |
In mypy, anything that accepts unicode is also deemed to accept str (even though that's a bit of a lie). So the union would be unneeded. |
@gvanrossum Thanks for the explanation! Does that suggest typeshed should use https://github.com/python/typeshed/blob/39325bf159e9af94e7aad5086b713ec03a23e6a3/stdlib/2and3/argparse.pyi#L49 (We tend to use |
I think the pytype folks would prefer the status quo. Also, we still
haven't come up with the final solution for the str/unicode/bytes issue,
and it would be better to wait with massive changes until the design is
settled.
FWIW I think unicode_literals was a bad idea and I now count it as an
anti-pattern. Though you may be stuck with it.
Still, for `**kwds` mypy should be able to fix this (but it's just me ATM
while Jukka is on vacation so don't expect instant fixes).
|
@gvanrossum Unfortunately a284c48 didn't fix this issue, it fixed passing a |
Reopening, since I rolled back PR #1971. |
@gvanrossum Any more info on what broke? Happy to fix it up. |
This is the prime example: #1971 (comment) |
@gvanrossum OK digging into this a bit it seems that in Python 2 type of kwargs should be |
I don't think you can do that without creating a custom subclass of Dict -- On Thu, Aug 4, 2016 at 11:16 AM, Roy Williams [email protected]
--Guido van Rossum (python.org/~guido) |
This may be something best resolved with the more precise types for Python 2's interconversion bytes <-> unicode when things are all ASCII -- @ddfisher will be writing up more about this soon. (There was a discussion back at PyCon that unfortunately wasn't written up electronically, but we just now reconstructed it and will post one or more issues with the specifics.) |
I think that it's too late to change this, and since this problem is specific to Python 2, it will gradually get less important. |
If a python 2 file is using
from __future__ import unicode_literals
breaks reading values out ofkwargs
using string literals.Tested using
e7ddab1acf44f02d63e8f5d70b1b07c70eeff73b
The text was updated successfully, but these errors were encountered: