-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Treat ascii-only literals as str, not unicode when using unicode_literals
#3619
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
I am not sure about the two questions, but it looks like supporting this in |
Hey our project cwltool has been We are trying to adpot use of But I'm not able to figure out how to deal with these issues.
Can you suggest any workaround until this issue is resolved and new release is made? |
TBH I would strongly advise against using `from __future__ import
unicode_literals`. It can be very confusing, and the issues you are running
into here are caused by invariance of Dict, see
http://mypy.readthedocs.io/en/latest/common_issues.html#invariance-vs-covariance
(tl;dr: Dict[unicode, X] is not compatible with Dict[str, X]).
|
Thanks @gvanrossum. Though |
On both python 2 and 3, or just 2? |
This is entirely a Py2 thing. |
This doesn't worth fixing since |
Many typeshed stubs only accept
str
when ascii-onlyunicode
values also work at runtime. This causes a lot of problems with code usingunicode_literals
, since generally most literals will haveunicode
as their type. A quick fix would be to inferstr
as the type for ascii-only string literals when usingunicode_literals
, but only then. This would cause some unsafety, but it may be worth it for users usingunicode_literals
. The type safe solution is to manually check everystr
argument type in the entire typeshed and potentially replace it withunicode
or similar, but this would be extremely painful and unlikely to happen any time soon. This would have no effect on code that doesn't useunicode_literals
.Example of how this would work:
Some open questions:
u'foo'
always have typeunicode
?x
inx = 'foo'
?The text was updated successfully, but these errors were encountered: