[BE] Fix SIM109 `compare-with-tuple` (#100337)
Use {replacement} instead of multiple equality comparisons
Pull Request resolved: https://github.com/pytorch/pytorch/pull/100337
Approved by: https://github.com/Skylion007
diff --git a/.flake8 b/.flake8
index 5171626..b5a61410 100644
--- a/.flake8
+++ b/.flake8
@@ -20,7 +20,7 @@
# these ignores are from flake8-logging-format; please fix!
G100,G101,G200,G201,G202
# these ignores are from flake8-simplify. please fix or ignore with commented reason
- SIM105,SIM108,SIM109,SIM110,SIM111,SIM113,SIM114,SIM115,SIM116,SIM117,SIM118,SIM119,SIM12,
+ SIM105,SIM108,SIM110,SIM111,SIM113,SIM114,SIM115,SIM116,SIM117,SIM118,SIM119,SIM12,
# flake8-simplify code styles
SIM102,SIM103,SIM106,SIM112,
per-file-ignores =
diff --git a/.github/scripts/filter_test_configs.py b/.github/scripts/filter_test_configs.py
index 521db7b..8ab6540 100755
--- a/.github/scripts/filter_test_configs.py
+++ b/.github/scripts/filter_test_configs.py
@@ -250,10 +250,7 @@
)
return filtered_test_matrix
- if (
- disabled_job_cfg == TEST_JOB_NAME
- or disabled_job_cfg == BUILD_AND_TEST_JOB_NAME
- ):
+ if disabled_job_cfg in (TEST_JOB_NAME, BUILD_AND_TEST_JOB_NAME):
print(
f"Issue {disabled_url} created by {author} has disabled all the test jobs for {workflow} / {job_name}"
)
@@ -263,7 +260,7 @@
if m:
disabled_job = m.group("job")
# Make sure that the job name is a valid test job name first before checking the config
- if disabled_job == TEST_JOB_NAME or disabled_job == BUILD_AND_TEST_JOB_NAME:
+ if disabled_job in (TEST_JOB_NAME, BUILD_AND_TEST_JOB_NAME):
disabled_cfg = m.group("cfg")
# Remove the disabled config from the test matrix
filtered_test_matrix["include"] = [
diff --git a/pyproject.toml b/pyproject.toml
index 5bb5e41..9767221 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -48,7 +48,6 @@
"SIM102", "SIM103", "SIM112", # flake8-simplify code styles
"SIM105", # these ignores are from flake8-simplify. please fix or ignore with commented reason
"SIM108",
- "SIM109",
"SIM110",
"SIM114", # Combine `if` branches using logical `or` operator
"SIM115",
diff --git a/test/functorch/test_vmap.py b/test/functorch/test_vmap.py
index c0952e8..faf465a 100644
--- a/test/functorch/test_vmap.py
+++ b/test/functorch/test_vmap.py
@@ -5018,7 +5018,7 @@
def f(x):
return Test.apply(x)
- if transform == grad or transform == grad_and_value:
+ if transform in (grad, grad_and_value):
input = torch.tensor(4.)
else:
input = torch.randn(5)
diff --git a/torch/_meta_registrations.py b/torch/_meta_registrations.py
index 1708e03..ea7254e 100644
--- a/torch/_meta_registrations.py
+++ b/torch/_meta_registrations.py
@@ -1625,7 +1625,7 @@
max_indices = indices.new_empty(0)
else:
fast_path_sum = is_fast_path(weight, per_sample_weights, output, padding_idx)
- if mode == MODE_MEAN or mode == MODE_MAX or not fast_path_sum:
+ if mode in (MODE_MEAN, MODE_MAX) or not fast_path_sum:
offset2bag = offsets.new_empty(indices.size(0))
else:
offset2bag = offsets.new_empty(0)
diff --git a/torch/utils/hipify/hipify_python.py b/torch/utils/hipify/hipify_python.py
index c9dda4d..4d3ad7b 100755
--- a/torch/utils/hipify/hipify_python.py
+++ b/torch/utils/hipify/hipify_python.py
@@ -278,7 +278,7 @@
char = string[i]
# Handle Templating Arguments
- if status == START or status == AT_TEMPLATE:
+ if status in (START, AT_TEMPLATE):
if char == ">":
if status == START:
status = AT_TEMPLATE