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-13 01:48:55 +00:00
committed by PyTorch MergeBot
parent a33f85e791
commit 8de85896e0
78 changed files with 166 additions and 164 deletions

View File

@ -4162,7 +4162,7 @@ class TestBinaryUfuncs(TestCase):
for i in complex_exponents if exp_dtype.is_complex else exponents:
out_dtype_scalar_exp = (
torch.complex128
if base_dtype.is_complex or type(i) == complex
if base_dtype.is_complex or type(i) is complex
else torch.float64
)
expected_scalar_exp = torch.from_numpy(np.float_power(to_np(base), i))
@ -4190,7 +4190,7 @@ class TestBinaryUfuncs(TestCase):
for i in complex_exponents if base_dtype.is_complex else exponents:
out_dtype_scalar_base = (
torch.complex128
if exp_dtype.is_complex or type(i) == complex
if exp_dtype.is_complex or type(i) is complex
else torch.float64
)
expected_scalar_base = torch.from_numpy(np.float_power(i, to_np(exp)))
@ -4205,9 +4205,9 @@ class TestBinaryUfuncs(TestCase):
def test_float_power_exceptions(self, device):
def _promo_helper(x, y):
for i in (x, y):
if type(i) == complex:
if type(i) is complex:
return torch.complex128
elif type(i) == torch.Tensor and i.is_complex():
elif type(i) is torch.Tensor and i.is_complex():
return torch.complex128
return torch.double