Skip to content

Make Python 2 support an extra #10183

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

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/source/cheat_sheet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ language represents various common types in Python 2.
many of the examples have a dual purpose: show how to write the
annotation, and show the inferred types.

.. note::

To check Python 2 code with mypy, you'll need to install mypy with
``pip install 'mypy[python2]'``.



Built-in types
**************
Expand Down
5 changes: 5 additions & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ For more information on how to use these flags, see :ref:`version_and_platform_c

Equivalent to running :option:`--python-version 2.7 <--python-version>`.

.. note::

To check Python 2 code with mypy, you'll need to install mypy with
``pip install 'mypy[python2]'``.

.. option:: --platform PLATFORM

This flag will make mypy type check your code as if it were
Expand Down
3 changes: 3 additions & 0 deletions docs/source/python2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ annotations are given in comments, since the function annotation
syntax was introduced in Python 3. The comment-based syntax is
specified in :pep:`484`.

Mypy requires typed-ast in order to check Python 2 code. You can install it
using ``pip install 'mypy[python2]'``.

Run mypy in Python 2 mode by using the :option:`--py2 <mypy --py2>` option::

$ mypy --py2 program.py
Expand Down
3 changes: 2 additions & 1 deletion mypy/fastparse2.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
from typed_ast import ast35 # type: ignore[attr-defined] # noqa: F401
except ImportError:
print('The typed_ast package is not installed.\n'
'You can install it with `python3 -m pip install typed-ast`.',
'For Python 2 support, install mypy using `python3 -m pip install "mypy[python2]"`'
'Alternatively, you can install typed_ast with `python3 -m pip install typed-ast`.',
file=sys.stderr)
else:
print('You need a more recent version of the typed_ast package.\n'
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ def run(self):
classifiers=classifiers,
cmdclass=cmdclass,
# When changing this, also update mypy-requirements.txt.
install_requires=['typed_ast >= 1.4.0, < 1.5.0',
install_requires=["typed_ast >= 1.4.0, < 1.5.0; python_version<'3.8'",
'typing_extensions>=3.7.4',
'mypy_extensions >= 0.4.3, < 0.5.0',
'types-typing-extensions>=3.7.0',
'types-mypy-extensions>=0.4.0',
'toml',
],
# Same here.
extras_require={'dmypy': 'psutil >= 4.0'},
extras_require={'dmypy': 'psutil >= 4.0', 'python2': 'typed_ast >= 1.4.0, < 1.5.0'},
python_requires=">=3.5",
include_package_data=True,
project_urls={
Expand Down