Enable ruff rule E721 (#165162)

`E721` checks for object type comparisons using == and other comparison operators. This is useful because it is recommended to use `is` for type comparisons.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/165162
Approved by: https://github.com/Skylion007
This commit is contained in:
Yuanyuan Chen
2025-10-11 06:43:53 +00:00
committed by PyTorch MergeBot
parent 220a34118f
commit 9e7c19f72b
78 changed files with 166 additions and 164 deletions

View File

@ -367,7 +367,7 @@ class DeepSpeech(nn.Module):
"""
seq_len = input_length
for m in self.conv.modules():
if type(m) == nn.modules.conv.Conv2d:
if type(m) is nn.modules.conv.Conv2d:
seq_len = (
seq_len
+ 2 * m.padding[1]

View File

@ -66,7 +66,7 @@ class GroupedSetup:
def __post_init__(self) -> None:
for field in dataclasses.fields(self):
assert field.type == str
assert field.type is str
value: str = getattr(self, field.name)
object.__setattr__(self, field.name, textwrap.dedent(value))

View File

@ -113,7 +113,7 @@ class TorchBenchmarkBase(torch.nn.Module):
value = kargs[key]
test_name_str.append(
("" if key in skip_key_list else key)
+ str(value if type(value) != bool else int(value))
+ str(value if type(value) is not bool else int(value))
)
name = (self.module_name() + "_" + "_".join(test_name_str)).replace(" ", "")
return name

View File

@ -125,7 +125,7 @@ class CatBenchmark(op_bench.TorchBenchmarkBase):
random.seed(42)
inputs = []
gen_sizes = []
if type(sizes) == list and N == -1:
if type(sizes) is list and N == -1:
gen_sizes = sizes
else:
for i in range(N):

View File

@ -61,7 +61,7 @@ class StackBenchmark(op_bench.TorchBenchmarkBase):
random.seed(42)
inputs = []
gen_sizes = []
if type(sizes) == list and N == -1:
if type(sizes) is list and N == -1:
gen_sizes = sizes
else:
for i in range(N):