Skip to content

Commit 2af8c6a

Browse files
authored
Bump minimal supported Python version from 3.8 to 3.10 (#2221)
Since 2.9 release upstream set min Python version to 3.10 pytorch/pytorch#162310. We should align linters and scripts. Bumping linters also enables new lints, such as [B905](https://docs.astral.sh/ruff/rules/zip-without-explicit-strict/), which will not be fixed in this PR. This lint is xfailed in upstream too
1 parent 3dc95ef commit 2af8c6a

15 files changed

+36
-306
lines changed

.github/scripts/microbench_summary.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import argparse
1515
import bisect
1616
from pathlib import Path
17-
from typing import Dict, List
1817

1918
def main():
2019
parser = argparse.ArgumentParser(
@@ -214,7 +213,7 @@ def get_op_pattern(base_op_name: str, get_backward: bool) -> tuple:
214213
else:
215214
return (base_op_name, f"{base_op_name} ")
216215

217-
def process_l1_loss(content: str, case_name: str, data: List, columns: List):
216+
def process_l1_loss(content: str, case_name: str, data: list, columns: list):
218217
shape_matches = list(re.finditer(r"(shape\s*[:=].*?)(?=\n\S|$)", content))
219218
shape_lines = [match.group(0) for match in shape_matches]
220219
shape_positions = [match.start() for match in shape_matches]
@@ -281,7 +280,7 @@ def process_l1_loss(content: str, case_name: str, data: List, columns: List):
281280

282281
data.append([record.get(col, "") for col in columns])
283282

284-
def extract_times(content: str, pattern: str, get_backward: bool) -> List:
283+
def extract_times(content: str, pattern: str, get_backward: bool) -> list:
285284
lines = content.split('\n')
286285
results = []
287286
for line in lines:
@@ -297,8 +296,8 @@ def extract_times(content: str, pattern: str, get_backward: bool) -> List:
297296

298297
return results
299298

300-
def create_record(params: Dict, case_name: str, op_name: str,
301-
backward: str, time_us: float) -> Dict:
299+
def create_record(params: dict, case_name: str, op_name: str,
300+
backward: str, time_us: float) -> dict:
302301
return {
303302
"P": params.get("p", ""),
304303
**params,
@@ -316,7 +315,7 @@ def convert_to_us(value: float, unit: str) -> float:
316315
return value * 1_000_000
317316
return value
318317

319-
def extract_params(text: str) -> Dict:
318+
def extract_params(text: str) -> dict:
320319
params = {}
321320
pairs = re.split(r'[;]', text.strip())
322321

.github/scripts/op_perf_comparison.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def preprocess_row(row):
2626
def display_row(record):
2727
formatted = {}
2828
for key, value in record.items():
29-
if isinstance(value, (list, tuple, dict)):
29+
if isinstance(value, list | tuple | dict):
3030
formatted[key] = str(value)
3131
elif value == "NULL":
3232
formatted[key] = "NULL"

.lintrunner.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ init_command = [
3434
'mccabe==0.7.0',
3535
'pycodestyle==2.11.1',
3636
'pyflakes==3.1.0',
37-
'torchfix==0.4.0 ; python_version >= "3.9" and python_version < "3.13"',
37+
'torchfix==0.4.0 ; python_version < "3.13"',
3838
]
3939

4040

@@ -83,11 +83,11 @@ init_command = [
8383
'python3',
8484
'tools/linter/adapters/pip_init.py',
8585
'--dry-run={{DRYRUN}}',
86-
'numpy==1.26.4 ; python_version >= "3.9" and python_version <= "3.11"',
86+
'numpy==1.26.4 ; python_version <= "3.11"',
8787
'numpy==2.1.0 ; python_version >= "3.12"',
8888
'expecttest==0.3.0',
8989
'mypy==1.13.0',
90-
'sympy==1.13.0 ; python_version >= "3.9"',
90+
'sympy==1.13.0',
9191
'types-requests==2.27.25',
9292
'types-PyYAML==6.0.7',
9393
'types-tabulate==0.8.8',

mypy-strict.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# files.
77

88
[mypy]
9-
python_version = 3.8
9+
python_version = 3.10
1010
plugins = mypy_plugins/check_mypy_version.py, numpy.typing.mypy_plugin
1111

1212
cache_dir = .mypy_cache/strict

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ignore = [
3434
"B023",
3535
"B028", # No explicit `stacklevel` keyword argument found
3636
"B904", # Migrate from TRY200
37+
"B905", # Python>=3.10 specific suppressions
3738
"E402",
3839
"C408", # C408 ignored because we like the dict keyword argument syntax
3940
"E501", # E501 is not flexible enough, we're using B950 instead

test/xpu/distributed/test_c10d_ops_xccl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,8 @@ def test_all_to_all_single_none(self):
918918
out = torch.zeros(self.world_size, 2, dtype=send.dtype).to(device)
919919
dist.all_to_all_single(out, send)
920920
self.assertEqual(
921-
out.tolist(), list(zip(range(self.world_size), range(self.world_size)))
921+
out.tolist(),
922+
list(zip(range(self.world_size), range(self.world_size))),
922923
)
923924

924925

test/xpu/test_modules_xpu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def _test_multiple_device_transfer(self, device, dtype, module_info, training):
270270
if torch.cuda.device_count() >= 2:
271271
# === test cross-GPU transfer works
272272
def _to_device1(objs):
273-
if isinstance(objs, (tuple, list)):
273+
if isinstance(objs, tuple | list):
274274
return type(objs)(_to_device1(item) for item in objs)
275275
elif isinstance(objs, dict):
276276
return {name: _to_device1(item) for name, item in objs.items()}

test/xpu/test_tensor_creation_ops_xpu.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import unittest
88
import warnings
99
from itertools import combinations, combinations_with_replacement, permutations, product
10-
from typing import Any, Dict, List, Tuple
10+
from typing import Any
1111

1212
import numpy as np
1313
import torch
@@ -4852,11 +4852,11 @@ def test_astensor_consistency(self, device):
48524852
True,
48534853
42,
48544854
1.0,
4855-
# Homogeneous Lists
4855+
# Homogeneous lists
48564856
[True, True, False],
48574857
[1, 2, 3, 42],
48584858
[0.0, 1.0, 2.0, 3.0],
4859-
# Mixed Lists
4859+
# Mixed lists
48604860
[True, False, 0],
48614861
[0.0, True, False],
48624862
[0, 1.0, 42],
@@ -4894,7 +4894,7 @@ def test_numpy_scalars(self, device):
48944894
def test_default_device(self, device):
48954895
original = torch.arange(5)
48964896

4897-
examples: List[Tuple[Any, Dict]] = [
4897+
examples: list[tuple[Any, dict]] = [
48984898
(3, {}),
48994899
(original, {}),
49004900
(to_numpy(original), {}),

test/xpu/test_torch_xpu.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from functools import partial
2424
from itertools import chain, combinations, permutations, product
2525
from multiprocessing.reduction import ForkingPickler
26-
from typing import Tuple
2726

2827
import numpy as np
2928
import torch
@@ -120,10 +119,8 @@
120119
torch._C._get_privateuse1_backend_name(),
121120
)
122121

123-
from typing import List
124122

125-
126-
def my_get_all_device_types_xpu() -> List[str]:
123+
def my_get_all_device_types_xpu() -> list[str]:
127124
devices = [
128125
"cpu",
129126
]
@@ -487,7 +484,7 @@ def test_set_storage(self, device, dtype):
487484

488485
def _check_storage_meta(self, s, s_check):
489486
self.assertTrue(
490-
isinstance(s, (torch.UntypedStorage, torch.TypedStorage))
487+
isinstance(s, torch.UntypedStorage | torch.TypedStorage)
491488
and isinstance(s_check, type(s)),
492489
(
493490
"s and s_check must both be one of UntypedStorage or "
@@ -4138,7 +4135,7 @@ def test_errors_index_copy(self, device):
41384135

41394136
def _prepare_data_for_index_copy_and_add_deterministic(
41404137
self, dim: int, device: torch.device
4141-
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
4138+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
41424139
assert dim >= 0 and dim < 3
41434140
a = [5, 4, 3]
41444141
a[dim] = 2000

tools/linter/adapters/_linter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from functools import cached_property
1313
from pathlib import Path
1414
from tokenize import generate_tokens, TokenInfo
15-
from typing import Any, Iterator, Sequence
15+
from typing import Any
16+
from collections.abc import Iterator, Sequence
1617
from typing_extensions import Never
1718

1819

0 commit comments

Comments
 (0)