Skip to content

Commit

Permalink
[BE] Enable ruff's UP rules in pyproject.toml (pytorch#105437)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinchuby authored and pytorchmergebot committed Jul 21, 2023
1 parent 6b2d48e commit de8bd10
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ ignore = [
"SIM116", # Disable Use a dictionary instead of consecutive `if` statements
"SIM117",
"SIM118",
"UP006", # keep-runtime-typing
"UP007", # keep-runtime-typing
]
line-length = 120
select = [
Expand All @@ -66,13 +68,21 @@ select = [
"SIM1",
"W",
# Not included in flake8
"UP",
"PERF",
"PLE",
"TRY302",
]

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
"test/jit/**" = [
"UP", # We don't want to modify the jit test as they test specify syntax
]
"torch/onnx/**" = [
"UP037", # ONNX does runtime type checking
]

"torchgen/api/types/__init__.py" = [
"F401",
"F403",
Expand All @@ -81,3 +91,6 @@ select = [
"F401",
"F403",
]
"torch/utils/collect_env.py" = [
"UP", # collect_env.py needs to work with older versions of Python
]
2 changes: 1 addition & 1 deletion test/inductor/test_cpu_repro.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def fn(x):

numerical_testsuit = [4.4, 4.5, 4.6, 5.5]
for numerical_number in numerical_testsuit:
x = torch.ones((17)) * numerical_number
x = torch.ones(17) * numerical_number
with config.patch({"cpp.simdlen": None}):
torch._dynamo.reset()
metrics.reset()
Expand Down
2 changes: 1 addition & 1 deletion test/mobile/test_lite_script_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class TestLiteScriptModule(TestCase):

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

class MyTestModule(torch.nn.Module):
def forward(self, a: torch.Tensor):
Expand Down
5 changes: 3 additions & 2 deletions test/nn/test_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,9 +1209,10 @@ def expected_output(dim, dtype):
return torch.stack([col, col + 2], 1).view(2, 2, 2, 2)

if adaptive:
cls_name = 'AdaptiveMaxPool{}d'.format(num_dim)
cls_name = 'AdaptiveMaxPool{}d'.format(num_dim) # noqa: UP032
else:
cls_name = 'MaxPool{}d'.format(num_dim)
# FIXME(#105716): Test fails when using f-string
cls_name = 'MaxPool{}d'.format(num_dim) # noqa: UP032
module_cls = getattr(nn, cls_name)
module = module_cls(2, return_indices=True).to(device, dtype=dtype)
numel = 4 ** (num_dim + 1)
Expand Down
2 changes: 1 addition & 1 deletion test/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14257,7 +14257,7 @@ def test_non_primitive_types(x):
self.assertEqual(out, torch.tensor(6.0))

def test_namedtuple_type_inference(self):
_AnnotatedNamedTuple = NamedTuple('_NamedTupleAnnotated', [('value', int)])
_AnnotatedNamedTuple = NamedTuple('_NamedTupleAnnotated', [('value', int)]) # noqa: UP014
_UnannotatedNamedTuple = namedtuple('_NamedTupleUnAnnotated', ['value'])

def test_check_named_tuple_value():
Expand Down

0 comments on commit de8bd10

Please sign in to comment.