Skip to content

Commit 82aaf64

Browse files
cyyeverpytorchmergebot
authored andcommitted
[3/N] Apply py39 ruff fixes (pytorch#142115)
Fixes #ISSUE_NUMBER Pull Request resolved: pytorch#142115 Approved by: https://github.com/ezyang
1 parent f7e621c commit 82aaf64

31 files changed

+137
-91
lines changed

tools/autograd/gen_annotated_fn_args.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import os
2121
import textwrap
2222
from collections import defaultdict
23-
from typing import Any, Sequence, TYPE_CHECKING
23+
from typing import Any, TYPE_CHECKING
2424

2525
import torchgen.api.python as python
2626
from torchgen.context import with_native_function
@@ -39,6 +39,8 @@
3939

4040

4141
if TYPE_CHECKING:
42+
from collections.abc import Sequence
43+
4244
from torchgen.model import Argument, BaseOperatorName, NativeFunction
4345

4446

tools/autograd/gen_autograd_functions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from __future__ import annotations
99

10-
from typing import Sequence
10+
from typing import TYPE_CHECKING
1111

1212
from torchgen.api.autograd import (
1313
Derivative,
@@ -47,6 +47,10 @@
4747
from .gen_inplace_or_view_type import VIEW_FUNCTIONS
4848

4949

50+
if TYPE_CHECKING:
51+
from collections.abc import Sequence
52+
53+
5054
FUNCTION_DECLARATION = CodeTemplate(
5155
"""\
5256
#ifdef _WIN32

tools/autograd/gen_python_functions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import itertools
3737
import re
3838
from collections import defaultdict
39-
from typing import Callable, Iterable, Sequence
39+
from typing import Callable, TYPE_CHECKING
4040

4141
import yaml
4242

@@ -76,6 +76,10 @@
7676
from .gen_trace_type import should_trace
7777

7878

79+
if TYPE_CHECKING:
80+
from collections.abc import Iterable, Sequence
81+
82+
7983
#
8084
# declarations blocklist
8185
# We skip codegen for these functions, for various reasons.

tools/autograd/gen_trace_type.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import itertools
4-
from typing import Sequence
4+
from typing import TYPE_CHECKING
55

66
from torchgen.api import cpp
77
from torchgen.api.types import DispatcherSignature
@@ -11,6 +11,10 @@
1111
from torchgen.utils import FileManager
1212

1313

14+
if TYPE_CHECKING:
15+
from collections.abc import Sequence
16+
17+
1418
# Note [Manual Backend kernels]
1519
# For these ops, we want to manually register to dispatch key Backend and
1620
# skip codegen-ed registeration to all keys before Backend.

tools/autograd/gen_variable_type.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from __future__ import annotations
3030

3131
import re
32-
from typing import Callable, Sequence
32+
from typing import Callable, TYPE_CHECKING
3333

3434
from torchgen.api import cpp
3535
from torchgen.api.autograd import (
@@ -105,6 +105,10 @@
105105
)
106106

107107

108+
if TYPE_CHECKING:
109+
from collections.abc import Sequence
110+
111+
108112
# We don't set or modify grad_fn on these methods. Generally, they return
109113
# tensors that have requires_grad=False. In-place functions listed here will
110114
# not examine or modify requires_grad or grad_fn.

tools/autograd/load_derivatives.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from __future__ import annotations
77

88
import re
9-
from collections import defaultdict
10-
from typing import Any, Counter, Dict, Sequence, Set, Tuple
9+
from collections import Counter, defaultdict
10+
from typing import Any, TYPE_CHECKING
1111

1212
import yaml
1313

@@ -53,7 +53,11 @@
5353
from torchgen.yaml_utils import YamlLoader
5454

5555

56-
DerivativeRet = Tuple[Dict[FunctionSchema, Dict[str, DifferentiabilityInfo]], Set[str]]
56+
if TYPE_CHECKING:
57+
from collections.abc import Sequence
58+
59+
60+
DerivativeRet = tuple[dict[FunctionSchema, dict[str, DifferentiabilityInfo]], set[str]]
5761

5862
_GLOBAL_LOAD_DERIVATIVE_CACHE: dict[tuple[str, str], DerivativeRet] = {}
5963

@@ -631,7 +635,7 @@ def set_up_derivatives(
631635
raise RuntimeError(
632636
f"Not supported: for {specification},"
633637
f"output_differentiability must either be "
634-
f"List[bool] or a List[str] where each str is a "
638+
f"list[bool] or a list[str] where each str is a "
635639
f"condition. In the case where it is a condition, "
636640
f"we only support single-output functions. "
637641
f"Please file us an issue. "

tools/code_analyzer/gen_op_registration_allowlist.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212

1313
import argparse
1414
from collections import defaultdict
15-
from typing import Dict, Set
1615

1716
import yaml
1817

1918

20-
DepGraph = Dict[str, Set[str]]
19+
DepGraph = dict[str, set[str]]
2120

2221

2322
def canonical_name(opname: str) -> str:

tools/code_coverage/package/tool/print_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import os
44
import subprocess
5-
from typing import IO, Tuple
5+
from typing import IO
66

77
from ..oss.utils import get_pytorch_folder
88
from ..util.setting import SUMMARY_FOLDER_DIR, TestList, TestStatusType
99

1010

11-
CoverageItem = Tuple[str, float, int, int]
11+
CoverageItem = tuple[str, float, int, int]
1212

1313

1414
def key_by_percentage(x: CoverageItem) -> float:

tools/code_coverage/package/tool/summarize_jsons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from .parser.coverage_record import CoverageRecord
3232

3333

34-
# coverage_records: Dict[str, LineInfo] = {}
34+
# coverage_records: dict[str, LineInfo] = {}
3535
covered_lines: dict[str, set[int]] = {}
3636
uncovered_lines: dict[str, set[int]] = {}
3737
tests_type: TestStatusType = {"success": set(), "partial": set(), "fail": set()}

tools/code_coverage/package/util/setting.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
from enum import Enum
5-
from typing import Dict, List, Set
65

76

87
# <project folder>
@@ -43,8 +42,8 @@ def __init__(
4342
self.test_type = test_type
4443

4544

46-
TestList = List[Test]
47-
TestStatusType = Dict[str, Set[str]]
45+
TestList = list[Test]
46+
TestStatusType = dict[str, set[str]]
4847

4948

5049
# option

0 commit comments

Comments
 (0)