Skip to content

Commit 4adb5e4

Browse files
authored
Make Python 2 support an extra (#10183)
Resolves #10124 Co-authored-by: hauntsaninja <>
1 parent 474fd5c commit 4adb5e4

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

docs/source/cheat_sheet.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ language represents various common types in Python 2.
1313
many of the examples have a dual purpose: show how to write the
1414
annotation, and show the inferred types.
1515

16+
.. note::
17+
18+
To check Python 2 code with mypy, you'll need to install mypy with
19+
``pip install 'mypy[python2]'``.
20+
21+
1622

1723
Built-in types
1824
**************

docs/source/command_line.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ For more information on how to use these flags, see :ref:`version_and_platform_c
232232

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

235+
.. note::
236+
237+
To check Python 2 code with mypy, you'll need to install mypy with
238+
``pip install 'mypy[python2]'``.
239+
235240
.. option:: --platform PLATFORM
236241

237242
This flag will make mypy type check your code as if it were

docs/source/python2.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ annotations are given in comments, since the function annotation
88
syntax was introduced in Python 3. The comment-based syntax is
99
specified in :pep:`484`.
1010

11+
Mypy requires typed-ast in order to check Python 2 code. You can install it
12+
using ``pip install 'mypy[python2]'``.
13+
1114
Run mypy in Python 2 mode by using the :option:`--py2 <mypy --py2>` option::
1215

1316
$ mypy --py2 program.py

mypy/fastparse2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
from typed_ast import ast35 # type: ignore[attr-defined] # noqa: F401
6969
except ImportError:
7070
print('The typed_ast package is not installed.\n'
71-
'You can install it with `python3 -m pip install typed-ast`.',
71+
'For Python 2 support, install mypy using `python3 -m pip install "mypy[python2]"`'
72+
'Alternatively, you can install typed_ast with `python3 -m pip install typed-ast`.',
7273
file=sys.stderr)
7374
else:
7475
print('You need a more recent version of the typed_ast package.\n'

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ def run(self):
191191
classifiers=classifiers,
192192
cmdclass=cmdclass,
193193
# When changing this, also update mypy-requirements.txt.
194-
install_requires=['typed_ast >= 1.4.0, < 1.5.0',
194+
install_requires=["typed_ast >= 1.4.0, < 1.5.0; python_version<'3.8'",
195195
'typing_extensions>=3.7.4',
196196
'mypy_extensions >= 0.4.3, < 0.5.0',
197197
'types-typing-extensions>=3.7.0',
198198
'types-mypy-extensions>=0.4.0',
199199
'toml',
200200
],
201201
# Same here.
202-
extras_require={'dmypy': 'psutil >= 4.0'},
202+
extras_require={'dmypy': 'psutil >= 4.0', 'python2': 'typed_ast >= 1.4.0, < 1.5.0'},
203203
python_requires=">=3.5",
204204
include_package_data=True,
205205
project_urls={

0 commit comments

Comments
 (0)