Skip to content

Bad typing for Python 2.7 with unicode_literals #5098

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
ikonst opened this issue May 23, 2018 · 4 comments
Closed

Bad typing for Python 2.7 with unicode_literals #5098

ikonst opened this issue May 23, 2018 · 4 comments

Comments

@ikonst
Copy link
Contributor

ikonst commented May 23, 2018

Consider:

from __future__ import unicode_literals
import sys

print(sys.modules['sys'])

mypy --py2 unicode_literals.py results in:

unicode_literals.py:4: error: Invalid index type "unicode" for "Dict[str, Any]"; expected type "str"

However, python2.7 unicode_literals.py results in:

<module 'sys' (built-in)>
@gvanrossum
Copy link
Member

gvanrossum commented May 23, 2018 via email

@Michael0x2a
Copy link
Collaborator

I believe mypy currently doesn't support unicode_literals: there's some related discussion here and here.

Maybe there's an opportunity to do some usability enhancement here? If we're not planning on supporting unicode_literals any time soon, maybe we can have mypy report a warning when it detects some code using it/link to something in the docs.

@gvanrossum
Copy link
Member

gvanrossum commented May 23, 2018 via email

@ilevkivskyi
Copy link
Member

This is essentially a duplicate of #2536, so I am closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants