Skip to content
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

Make Python 2 support an "extra" in 0.900 #10124

Closed
hauntsaninja opened this issue Feb 21, 2021 · 9 comments · Fixed by #10183
Closed

Make Python 2 support an "extra" in 0.900 #10124

hauntsaninja opened this issue Feb 21, 2021 · 9 comments · Fixed by #10183
Labels

Comments

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 21, 2021

The motivation for this is that typed-ast is a pain to deal with (it's just broken again on latest Python 3.10, and was a pain to deal with for Python 3.9, e.g. preventing Windows installs for some months) and Python 2 usage is ever dwindling*. Since mypy 0.900 will basically force all users to revisit how they install mypy, it seems like a good time to force the remaining users of mypy with Python 2 to change to pip install 'mypy[python2]'.

@JukkaL thoughts?

*pypistats.org tells me Python 2 usage is down 40% in the last six months (based on Python 2 downloads of six)

@TH3CHARLie
Copy link
Collaborator

strongly agreed

@henryiii
Copy link
Contributor

The current setup.py says that 3.5+ is required, and I don't see wheels for Python 2 anymore. Is Python 2 still supported? It says so in quite a few places, including the GitHub summary.

@JelleZijlstra
Copy link
Member

@henryiii Python 2 was never supported for running mypy, but mypy still supports checking Python 2 code. Shantanu's suggestion is to make the support for checking Python 2 an extra.

@henryiii
Copy link
Contributor

I just realized that 🤦 Thanks!

@henryiii
Copy link
Contributor

Though I'm confused about the comments covering typed ast. I still see type comments used once in a while in Python 3 only code?

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 21, 2021

The ast module in Python 3.8 added support for type comments. So we only need typed-ast when running on Python 3.7 and earlier, or when type checking Python 2 code (and running on any Python version).

Python 2 is still used a lot, so we can't stop supporting it in the near future. For example, about 10% of downloads for requests are for Python 2. I guess the main benefit of making Python 2 support optional would be that a broken typed-ast doesn't prevent installation of mypy on Python 3.8+, including alpha and beta releases? And typed-ast is unlikely to get broken on 3.7 and earlier, since these receive security fixes only.

I think that the proposal sounds reasonable, as long as we generate a helpful error message when running in Python 2 mode and typed-ast is not available. We should still make sure that typed-ast works on Python 3.10 at least, but it should be okay if it only gets fixed some time after the release of Python 3.10.0. It's too early to say if we will need Python 2 support when running on Python 3.11 (or whatever the next release after 3.10 will be called).

@henryiii
Copy link
Contributor

Then why not:

install_requires=["typed_ast >= 1.4.0, < 1.5.0; python_version < '3.8'",

I don't get why typed comments are "Python 2"; they are perfectly valid in Python 3 only code; in fact, they were the only way to do a variable annotation before 3.6, and they were faster than instantiating an object before Python 3.10 (or for a codebase requiring 3.7+ by using the future import).

@hauntsaninja
Copy link
Collaborator Author

@henryiii The ast module doesn't allow you to parse Python 2 code, so on all versions of Python, mypy uses typed-ast to parse Python 2 code. On Python 3.8+, this is the only thing we need typed-ast for, hence this issue.

@henryiii
Copy link
Contributor

Thanks for clearing up my confusion! :)

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

Successfully merging a pull request may close this issue.

5 participants