From 379622de482ec16dd1676ad6d183dcfca5203194 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Wed, 23 Jun 2021 19:43:43 -0700 Subject: [PATCH] Drop Python 3.5 support (#10706) --- build-requirements.txt | 1 - docs/source/class_basics.rst | 6 ------ docs/source/common_issues.rst | 6 +++--- docs/source/getting_started.rst | 2 +- docs/source/runtime_troubles.rst | 6 ------ mypy/build.py | 2 +- mypy/fastparse.py | 2 +- mypy/main.py | 4 ++-- mypy/stubtest.py | 14 ++------------ mypy/util.py | 10 +++------- setup.py | 7 +++---- test-requirements.txt | 3 +-- 12 files changed, 17 insertions(+), 46 deletions(-) diff --git a/build-requirements.txt b/build-requirements.txt index eee2f9da3fe3..aad1f8e59105 100644 --- a/build-requirements.txt +++ b/build-requirements.txt @@ -1,4 +1,3 @@ -r mypy-requirements.txt types-typed-ast>=1.4.0,<1.5.0 types-toml>=0.0 -types-enum34>=0.0; python_version == '3.5' diff --git a/docs/source/class_basics.rst b/docs/source/class_basics.rst index 330d9805be14..8e604427e683 100644 --- a/docs/source/class_basics.rst +++ b/docs/source/class_basics.rst @@ -127,12 +127,6 @@ particular attribute should not be set on instances: a.x = 1 # Error: Cannot assign to class variable "x" via instance print(a.x) # OK -- can be read through an instance -.. note:: - - If you need to support Python 3 versions 3.5.2 or earlier, you have - to import ``ClassVar`` from ``typing_extensions`` instead (available on - PyPI). If you use Python 2.7, you can import it from ``typing``. - It's not necessary to annotate all class variables using :py:data:`~typing.ClassVar`. An attribute without the :py:data:`~typing.ClassVar` annotation can still be used as a class variable. However, mypy won't prevent it from diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 0a513efc2d4f..58f8395091d0 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -14,7 +14,7 @@ Can't install mypy using pip If installation fails, you've probably hit one of these issues: -* Mypy needs Python 3.5 or later to run. +* Mypy needs Python 3.6 or later to run. * You may have to run pip like this: ``python3 -m pip install mypy``. @@ -428,8 +428,8 @@ More specifically, mypy will understand the use of :py:data:`sys.version_info` a import sys # Distinguishing between different versions of Python: - if sys.version_info >= (3, 5): - # Python 3.5+ specific definitions and imports + if sys.version_info >= (3, 8): + # Python 3.8+ specific definitions and imports elif sys.version_info[0] >= 3: # Python 3 specific definitions and imports else: diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 12c05c0d32e0..d180fcd70f3c 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -12,7 +12,7 @@ may not make much sense otherwise. Installing and running mypy *************************** -Mypy requires Python 3.5 or later to run. Once you've +Mypy requires Python 3.6 or later to run. Once you've `installed Python 3 `_, install mypy using pip: diff --git a/docs/source/runtime_troubles.rst b/docs/source/runtime_troubles.rst index 34d9dc795f0d..515a7985dcbe 100644 --- a/docs/source/runtime_troubles.rst +++ b/docs/source/runtime_troubles.rst @@ -94,12 +94,6 @@ Since code inside ``if TYPE_CHECKING:`` is not executed at runtime, it provides a convenient way to tell mypy something without the code being evaluated at runtime. This is most useful for resolving :ref:`import cycles `. -.. note:: - - Python 3.5.1 and below don't have :py:data:`~typing.TYPE_CHECKING`. An - alternative is to define a constant named ``MYPY`` that has the value - ``False`` at runtime. Mypy considers it to be ``True`` when type checking. - Class name forward references ----------------------------- diff --git a/mypy/build.py b/mypy/build.py index a39b78798d98..14bf1e68a51e 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -1091,7 +1091,7 @@ def _load_json_file(file: str, manager: BuildManager, manager.trace(log_success + data.rstrip()) try: result = json.loads(data) - except ValueError: # TODO: JSONDecodeError in 3.5 + except json.JSONDecodeError: manager.errors.set_file(file, None) manager.errors.report(-1, -1, "Error reading JSON file;" diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 15b86d71b3d2..ed85c5962424 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -1357,7 +1357,7 @@ def translate_expr_list(self, l: Sequence[ast3.expr]) -> List[Type]: def visit_raw_str(self, s: str) -> Type: # An escape hatch that allows the AST walker in fastparse2 to - # directly hook into the Python 3.5 type converter in some cases + # directly hook into the Python 3 type converter in some cases # without needing to create an intermediary `Str` object. _, typ = parse_type_comment(s.strip(), self.line, diff --git a/mypy/main.py b/mypy/main.py index da4eda6e04a0..ac71d035c75b 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -237,8 +237,8 @@ class PythonExecutableInferenceError(Exception): def python_executable_prefix(v: str) -> List[str]: if sys.platform == 'win32': # on Windows, all Python executables are named `python`. To handle this, there - # is the `py` launcher, which can be passed a version e.g. `py -3.5`, and it will - # execute an installed Python 3.5 interpreter. See also: + # is the `py` launcher, which can be passed a version e.g. `py -3.8`, and it will + # execute an installed Python 3.8 interpreter. See also: # https://docs.python.org/3/using/windows.html#python-launcher-for-windows return ['py', '-{}'.format(v)] else: diff --git a/mypy/stubtest.py b/mypy/stubtest.py index 7915e14f1551..2dde3e7f931e 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -38,17 +38,7 @@ def __repr__(self) -> str: MISSING = Missing() T = TypeVar("T") -if sys.version_info >= (3, 5, 3): - MaybeMissing = Union[T, Missing] -else: - # work around a bug in 3.5.2 and earlier's typing.py - class MaybeMissingMeta(type): - def __getitem__(self, arg: Any) -> Any: - return Union[arg, Missing] - - class MaybeMissing(metaclass=MaybeMissingMeta): # type: ignore - pass - +MaybeMissing = Union[T, Missing] _formatter = FancyFormatter(sys.stdout, sys.stderr, False) @@ -1069,7 +1059,7 @@ def get_typeshed_stdlib_modules(custom_typeshed_dir: Optional[str]) -> List[str] """Returns a list of stdlib modules in typeshed (for current Python version).""" stdlib_py_versions = mypy.modulefinder.load_stdlib_py_versions(custom_typeshed_dir) packages = set() - # Typeshed doesn't cover Python 3.5. + # Typeshed's minimum supported Python 3 is Python 3.6 if sys.version_info < (3, 6): version_info = (3, 6) else: diff --git a/mypy/util.py b/mypy/util.py index 79475972a57a..2c1ffbce43cf 100644 --- a/mypy/util.py +++ b/mypy/util.py @@ -393,13 +393,9 @@ def get_unique_redefinition_name(name: str, existing: Container[str]) -> str: def check_python_version(program: str) -> None: """Report issues with the Python used to run mypy, dmypy, or stubgen""" # Check for known bad Python versions. - if sys.version_info[:2] < (3, 5): - sys.exit("Running {name} with Python 3.4 or lower is not supported; " - "please upgrade to 3.5 or newer".format(name=program)) - # this can be deleted once we drop support for 3.5 - if sys.version_info[:3] == (3, 5, 0): - sys.exit("Running {name} with Python 3.5.0 is not supported; " - "please upgrade to 3.5.1 or newer".format(name=program)) + if sys.version_info[:2] < (3, 6): + sys.exit("Running {name} with Python 3.5 or lower is not supported; " + "please upgrade to 3.6 or newer".format(name=program)) def count_stats(errors: List[str]) -> Tuple[int, int]: diff --git a/setup.py b/setup.py index 87e5b8432d34..ca3a7ebbace1 100644 --- a/setup.py +++ b/setup.py @@ -5,8 +5,8 @@ import os.path import sys -if sys.version_info < (3, 5, 0): - sys.stderr.write("ERROR: You need Python 3.5 or later to use mypy.\n") +if sys.version_info < (3, 6, 0): + sys.stderr.write("ERROR: You need Python 3.6 or later to use mypy.\n") exit(1) # we'll import stuff from the source tree, let's ensure is on the sys path @@ -162,7 +162,6 @@ def run(self): 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', @@ -198,7 +197,7 @@ def run(self): ], # Same here. extras_require={'dmypy': 'psutil >= 4.0', 'python2': 'typed_ast >= 1.4.0, < 1.5.0'}, - python_requires=">=3.5", + python_requires=">=3.6", include_package_data=True, project_urls={ 'News': 'http://mypy-lang.org/news.html', diff --git a/test-requirements.txt b/test-requirements.txt index 2d83221c2f7a..b5b9da8b0a24 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,8 +6,7 @@ flake8-bugbear; python_version >= '3.5' flake8-pyi>=20.5; python_version >= '3.6' lxml>=4.4.0 psutil>=4.0 -# pytest 6.2 does not support Python 3.5 -pytest>=6.1.0,<6.2.0 +pytest>=6.2.0,<7.0.0 pytest-xdist>=1.34.0,<2.0.0 pytest-forked>=1.3.0,<2.0.0 pytest-cov>=2.10.0,<3.0.0