Skip to content

Making it easier to use unicode_literals #2536

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
JukkaL opened this issue Dec 7, 2016 · 3 comments
Closed

Making it easier to use unicode_literals #2536

JukkaL opened this issue Dec 7, 2016 · 3 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 7, 2016

Currently using from __future__ import unicode_literals in Python 2 is kind of painful with mypy. Here are some potential issues:

  • Some typeshed stubs declare things to only accept str arguments, when in reality they also accept at least ascii-only unicode objects.
  • Mypy might not accept the implicit unicode literals in every context where a literal has a syntactic role (outside normal expressions), and b'foo' literals won't work in Python 3. String literal type escaping is an example.

It's fair to argue that using unicode_literals is a bad idea, but it's not uncommon to encounter real-world code using that, so getting mypy to work with it might be at least somewhat important.

@ddfisher
Copy link
Collaborator

ddfisher commented Dec 7, 2016

FWIW string literal type escaping has already been fixed: #2516

After that fix I did a quick grep of the codebase looking for other similar errors, and the only one I found is fixed in #2519.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Dec 7, 2016

This is still rejected by mypy when using --py2 --fast-parser:

from __future__ import unicode_literals

def f(x: 'int') -> int:   # invalid syntax
    return x + 1

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 29, 2020

This doesn't seem worth fixing any more, since Python 2 reached it's EoL and gradually the amount of code using unicode_literals is likely to decrease.

@JukkaL JukkaL closed this as completed Jan 29, 2020
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

3 participants