From dc5cda0cca429a3080f63e7b30b3e87d18df8601 Mon Sep 17 00:00:00 2001 From: Nikita Shulga Date: Wed, 19 Jan 2022 15:59:11 -0800 Subject: [PATCH] Update min python version to 3.7 in setup.py and mypy configs (#71494) Summary: As Python-3.6 have reached EOL Pull Request resolved: https://github.com/pytorch/pytorch/pull/71494 Reviewed By: atalman Differential Revision: D33667509 Pulled By: malfet fbshipit-source-id: ab1f03085cfb9161df77ba5ce373b81f5e7ef3ae (cherry picked from commit 60343166d97b1eb1649b29a78ad390d39926b642) --- mypy-strict.ini | 2 +- mypy.ini | 4 ++-- setup.py | 3 +-- test/test_jit.py | 4 +--- tools/fast_nvcc/fast_nvcc.py | 2 +- torch/_six.py | 2 -- torch/futures/__init__.py | 12 ++---------- torch/jit/_builtins.py | 4 +--- torch/utils/data/_typing.py | 24 ++++++++---------------- 9 files changed, 17 insertions(+), 40 deletions(-) diff --git a/mypy-strict.ini b/mypy-strict.ini index 857ef2b0486d5..d233600f37ee5 100644 --- a/mypy-strict.ini +++ b/mypy-strict.ini @@ -6,7 +6,7 @@ # files. [mypy] -python_version = 3.6 +python_version = 3.7 plugins = mypy_plugins/check_mypy_version.py cache_dir = .mypy_cache/strict diff --git a/mypy.ini b/mypy.ini index a0c41fac3d798..a3ec144806e48 100644 --- a/mypy.ini +++ b/mypy.ini @@ -44,8 +44,8 @@ files = exclude = torch/include/|torch/csrc/|torch/distributed/elastic/agent/server/api.py|torch/testing/_internal # Minimum version supported - variable annotations were introduced -# in Python 3.6 -python_version = 3.6 +# in Python 3.7 +python_version = 3.7 # diff --git a/setup.py b/setup.py index b4bf03dc172ba..aa1669a10d309 100644 --- a/setup.py +++ b/setup.py @@ -206,7 +206,7 @@ sys.exit(-1) import platform -python_min_version = (3, 6, 2) +python_min_version = (3, 7, 0) python_min_version_str = '.'.join(map(str, python_min_version)) if sys.version_info < python_min_version: print("You are using Python {}. Python >={} is required.".format(platform.python_version(), @@ -408,7 +408,6 @@ def build_deps(): # the list of runtime dependencies required by this built package install_requires = [ 'typing_extensions', - 'dataclasses; python_version < "3.7"' ] missing_pydep = ''' diff --git a/test/test_jit.py b/test/test_jit.py index ef549f996d49f..37cd9b5d53c04 100644 --- a/test/test_jit.py +++ b/test/test_jit.py @@ -80,7 +80,6 @@ # Torch from torch import Tensor from torch._C import TensorType, BoolType, parse_ir, _propagate_shapes -from torch._six import PY37 from torch.autograd import Variable from torch.jit.annotations import BroadcastingList2, BroadcastingList3, Any # noqa: F401 from torch.nn.utils.rnn import PackedSequence @@ -6473,8 +6472,7 @@ def func(a, b): checkMathWrap("ceil", ret_type="int") checkMathWrap("gcd", 2, is_float=False, ret_type="int") checkMath("isfinite", 1, ret_type="bool") - if PY37: - checkMathWrap("remainder", 2) + checkMathWrap("remainder", 2) checkMathWrap("factorial", 1, is_float=False, ret_type="int", vals=[(i, 0) for i in range(-2, 10)]) def test_if_nest_while(self): diff --git a/tools/fast_nvcc/fast_nvcc.py b/tools/fast_nvcc/fast_nvcc.py index 308bd65e9d658..f1bb4fa6c9e6c 100755 --- a/tools/fast_nvcc/fast_nvcc.py +++ b/tools/fast_nvcc/fast_nvcc.py @@ -533,7 +533,7 @@ def fast_nvcc( print_command_outputs(results) if config.table: write_log_csv(command_parts, results, filename=config.table) - return exit_code([dryrun_data] + results) + return exit_code([dryrun_data] + results) # type: ignore[arg-type, operator] def our_arg(arg: str) -> bool: diff --git a/torch/_six.py b/torch/_six.py index d8515d0a2b704..e288a1199b771 100644 --- a/torch/_six.py +++ b/torch/_six.py @@ -19,12 +19,10 @@ # SOFTWARE. import math -import sys inf = math.inf nan = math.nan string_classes = (str, bytes) -PY37 = sys.version_info[0] == 3 and sys.version_info[1] >= 7 def with_metaclass(meta: type, *bases) -> type: """Create a base class with a metaclass.""" diff --git a/torch/futures/__init__.py b/torch/futures/__init__.py index 5d1f72cea297c..ed4ec53a78e27 100644 --- a/torch/futures/__init__.py +++ b/torch/futures/__init__.py @@ -1,20 +1,12 @@ from typing import cast, Callable, Generic, List, Optional, Type, TypeVar, Union import torch -from torch._six import PY37 T = TypeVar("T") S = TypeVar("S") -if not PY37: - # Workaround for https://github.com/python/typing/issues/449 in Python 3.6 - from typing import GenericMeta - - class _PyFutureMeta(type(torch._C.Future), GenericMeta): # type: ignore[misc] - pass -else: - class _PyFutureMeta(type(torch._C.Future), type(Generic)): # type: ignore[misc, no-redef] - pass +class _PyFutureMeta(type(torch._C.Future), type(Generic)): # type: ignore[misc, no-redef] + pass class Future(torch._C.Future, Generic[T], metaclass=_PyFutureMeta): r""" diff --git a/torch/jit/_builtins.py b/torch/jit/_builtins.py index b879c521b7c24..2a3fd865adb16 100644 --- a/torch/jit/_builtins.py +++ b/torch/jit/_builtins.py @@ -5,7 +5,6 @@ import torch import torch.backends.cudnn as cudnn -from torch._six import PY37 from ..nn.modules.utils import _single, _pair, _triple, _quadruple, _list_with_default from collections import OrderedDict @@ -142,8 +141,7 @@ def register_all(mod): _builtin_ops.append((math.gcd, "aten::gcd")) _builtin_ops.append((math.isfinite, "aten::isfinite")) - if PY37: - _builtin_ops.append((math.remainder, "aten::mathremainder")) # type: ignore[attr-defined] + _builtin_ops.append((math.remainder, "aten::mathremainder")) # type: ignore[attr-defined] import torch.distributed.autograd as dist_autograd if dist_autograd.is_available(): diff --git a/torch/utils/data/_typing.py b/torch/utils/data/_typing.py index d222adf384b67..27aae4821ce97 100644 --- a/torch/utils/data/_typing.py +++ b/torch/utils/data/_typing.py @@ -9,25 +9,17 @@ from typing import (Any, Dict, Iterator, Generic, List, Set, Tuple, TypeVar, Union, get_type_hints) from typing import _eval_type, _tp_cache, _type_check, _type_repr # type: ignore[attr-defined] - -try: # Python > 3.6 - from typing import ForwardRef # type: ignore[attr-defined] -except ImportError: # Python 3.6 - from typing import _ForwardRef as ForwardRef # type: ignore[attr-defined] +from typing import ForwardRef # TODO: Use TypeAlias when Python 3.6 is deprecated # Please check [Note: TypeMeta and TypeAlias] -try: - from typing import GenericMeta # Python 3.6 - _GenericAlias = GenericMeta -except ImportError: # Python > 3.6 - # In case of metaclass conflict due to ABCMeta or _ProtocolMeta - # For Python 3.9, only Protocol in typing uses metaclass - from abc import ABCMeta - from typing import _ProtocolMeta, _GenericAlias # type: ignore[attr-defined, no-redef] - - class GenericMeta(_ProtocolMeta, ABCMeta): # type: ignore[no-redef] - pass +# In case of metaclass conflict due to ABCMeta or _ProtocolMeta +# For Python 3.9, only Protocol in typing uses metaclass +from abc import ABCMeta +from typing import _ProtocolMeta, _GenericAlias # type: ignore[attr-defined, no-redef] + +class GenericMeta(_ProtocolMeta, ABCMeta): # type: ignore[no-redef] + pass import torch