Skip to content

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

Closed

Description

@hauntsaninja

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)

Activity

  1. TH3CHARLie commented on Feb 21, 2021

    @TH3CHARLie
    Collaborator

    strongly agreed

  2. henryiii commented on Feb 21, 2021

    @henryiii
    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.

  3. JelleZijlstra commented on Feb 21, 2021

    @JelleZijlstra
    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.

  4. henryiii commented on Feb 21, 2021

    @henryiii
    Contributor

    I just realized that 🤦 Thanks!

  5. henryiii commented on Feb 21, 2021

    @henryiii
    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?

  6. JukkaL commented on Feb 21, 2021

    @JukkaL
    Collaborator

    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).

  7. henryiii commented on Feb 21, 2021

    @henryiii
    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).

  8. hauntsaninja commented on Feb 21, 2021

    @hauntsaninja
    CollaboratorAuthor

    @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.

  9. henryiii commented on Feb 21, 2021

    @henryiii
    Contributor

    Thanks for clearing up my confusion! :)

  10. added a commit that references this issue on Mar 7, 2021
    a702021
  11. added a commit that references this issue on Mar 8, 2021
    4adb5e4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions