Skip to content

Commit de8bd10

Browse files
justinchubypytorchmergebot
authored andcommittedJul 21, 2023
[BE] Enable ruff's UP rules in pyproject.toml (pytorch#105437)
Signed-off-by: Justin Chu <justinchu@microsoft.com> Pull Request resolved: pytorch#105437 Approved by: https://github.com/huydhn, https://github.com/malfet, https://github.com/Skylion007
1 parent 6b2d48e commit de8bd10

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed
 

‎pyproject.toml

+13
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ ignore = [
5555
"SIM116", # Disable Use a dictionary instead of consecutive `if` statements
5656
"SIM117",
5757
"SIM118",
58+
"UP006", # keep-runtime-typing
59+
"UP007", # keep-runtime-typing
5860
]
5961
line-length = 120
6062
select = [
@@ -66,13 +68,21 @@ select = [
6668
"SIM1",
6769
"W",
6870
# Not included in flake8
71+
"UP",
6972
"PERF",
7073
"PLE",
7174
"TRY302",
7275
]
7376

7477
[tool.ruff.per-file-ignores]
7578
"__init__.py" = ["F401"]
79+
"test/jit/**" = [
80+
"UP", # We don't want to modify the jit test as they test specify syntax
81+
]
82+
"torch/onnx/**" = [
83+
"UP037", # ONNX does runtime type checking
84+
]
85+
7686
"torchgen/api/types/__init__.py" = [
7787
"F401",
7888
"F403",
@@ -81,3 +91,6 @@ select = [
8191
"F401",
8292
"F403",
8393
]
94+
"torch/utils/collect_env.py" = [
95+
"UP", # collect_env.py needs to work with older versions of Python
96+
]

‎test/inductor/test_cpu_repro.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def fn(x):
518518

519519
numerical_testsuit = [4.4, 4.5, 4.6, 5.5]
520520
for numerical_number in numerical_testsuit:
521-
x = torch.ones((17)) * numerical_number
521+
x = torch.ones(17) * numerical_number
522522
with config.patch({"cpp.simdlen": None}):
523523
torch._dynamo.reset()
524524
metrics.reset()

‎test/mobile/test_lite_script_type.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class TestLiteScriptModule(TestCase):
1515

1616
def test_typing_namedtuple(self):
17-
myNamedTuple = NamedTuple('myNamedTuple', [('a', List[torch.Tensor])])
17+
myNamedTuple = NamedTuple('myNamedTuple', [('a', List[torch.Tensor])]) # noqa: UP014
1818

1919
class MyTestModule(torch.nn.Module):
2020
def forward(self, a: torch.Tensor):

‎test/nn/test_pooling.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1209,9 +1209,10 @@ def expected_output(dim, dtype):
12091209
return torch.stack([col, col + 2], 1).view(2, 2, 2, 2)
12101210

12111211
if adaptive:
1212-
cls_name = 'AdaptiveMaxPool{}d'.format(num_dim)
1212+
cls_name = 'AdaptiveMaxPool{}d'.format(num_dim) # noqa: UP032
12131213
else:
1214-
cls_name = 'MaxPool{}d'.format(num_dim)
1214+
# FIXME(#105716): Test fails when using f-string
1215+
cls_name = 'MaxPool{}d'.format(num_dim) # noqa: UP032
12151216
module_cls = getattr(nn, cls_name)
12161217
module = module_cls(2, return_indices=True).to(device, dtype=dtype)
12171218
numel = 4 ** (num_dim + 1)

‎test/test_jit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14257,7 +14257,7 @@ def test_non_primitive_types(x):
1425714257
self.assertEqual(out, torch.tensor(6.0))
1425814258

1425914259
def test_namedtuple_type_inference(self):
14260-
_AnnotatedNamedTuple = NamedTuple('_NamedTupleAnnotated', [('value', int)])
14260+
_AnnotatedNamedTuple = NamedTuple('_NamedTupleAnnotated', [('value', int)]) # noqa: UP014
1426114261
_UnannotatedNamedTuple = namedtuple('_NamedTupleUnAnnotated', ['value'])
1426214262

1426314263
def test_check_named_tuple_value():

0 commit comments

Comments
 (0)
Please sign in to comment.