Skip to content

Commit

Permalink
Update min python version to 3.7 in setup.py and mypy configs (pytorc…
Browse files Browse the repository at this point in the history
…h#71494)

Summary:
As Python-3.6 have reached EOL

Pull Request resolved: pytorch#71494

Reviewed By: atalman

Differential Revision: D33667509

Pulled By: malfet

fbshipit-source-id: ab1f03085cfb9161df77ba5ce373b81f5e7ef3ae
(cherry picked from commit 6034316)
  • Loading branch information
malfet authored and pytorchmergebot committed Jan 20, 2022
1 parent 06bc674 commit dc5cda0
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 40 deletions.
2 changes: 1 addition & 1 deletion mypy-strict.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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


#
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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 = '''
Expand Down
4 changes: 1 addition & 3 deletions test/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tools/fast_nvcc/fast_nvcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions torch/_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
12 changes: 2 additions & 10 deletions torch/futures/__init__.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down
4 changes: 1 addition & 3 deletions torch/jit/_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
24 changes: 8 additions & 16 deletions torch/utils/data/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit dc5cda0

Please sign in to comment.