diff --git a/docs/source/cheat_sheet.rst b/docs/source/cheat_sheet.rst index 0007f33bfcd4..db15a1a58e68 100644 --- a/docs/source/cheat_sheet.rst +++ b/docs/source/cheat_sheet.rst @@ -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 ************** diff --git a/docs/source/command_line.rst b/docs/source/command_line.rst index 31557511bb4a..27b370407d39 100644 --- a/docs/source/command_line.rst +++ b/docs/source/command_line.rst @@ -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 diff --git a/docs/source/python2.rst b/docs/source/python2.rst index 3e484fb3619f..67ea4f80d760 100644 --- a/docs/source/python2.rst +++ b/docs/source/python2.rst @@ -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 ` option:: $ mypy --py2 program.py diff --git a/mypy/fastparse2.py b/mypy/fastparse2.py index 670852f3bc7f..2bfea7df23b4 100644 --- a/mypy/fastparse2.py +++ b/mypy/fastparse2.py @@ -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' diff --git a/setup.py b/setup.py index af896c066195..c543b7512ac8 100644 --- a/setup.py +++ b/setup.py @@ -191,7 +191,7 @@ 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', @@ -199,7 +199,7 @@ def run(self): '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={