Skip to content

Commit 758a0a8

Browse files
XuehaiPanpytorchmergebot
authored andcommitted
[BE][Easy] enable ruff rule PIE790: unnecessary pass statement (pytorch#133200)
This PR removes unnecessary `pass` statement. This is semanticly safe because the bytecode for the Python code does not change. Note that if there is a docstring in the function, a empty function does not need a `pass` statement as placeholder. Pull Request resolved: pytorch#133200 Approved by: https://github.com/malfet, https://github.com/eqy, https://github.com/kit1980
1 parent 57d1ffc commit 758a0a8

File tree

87 files changed

+2
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2
-176
lines changed

.github/scripts/gitutils.py

-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ def wrapper(*args: List[Any], **kwargs: Dict[str, Any]) -> T:
445445
print(
446446
f'Attempt {idx} of {num_retries} to call {f.__name__} failed with "{e}"'
447447
)
448-
pass
449448
return cast(T, rc)
450449

451450
return wrapper

benchmarks/functional_autograd_benchmark/torchvision_models.py

-2
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,6 @@ class FCN(_SimpleSegmentationModel):
402402
aux_classifier (nn.Module, optional): auxiliary classifier used during training
403403
"""
404404

405-
pass
406-
407405

408406
class FCNHead(nn.Sequential):
409407
def __init__(self, in_channels, channels):

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ select = [
108108
"NPY",
109109
"PERF",
110110
"PGH004",
111+
"PIE790",
111112
"PIE794",
112113
"PIE800",
113114
"PIE804",

test/cpp/jit/tests_setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class FileSetup:
1818
def shutdown(self):
1919
if os.path.exists(self.path):
2020
os.remove(self.path)
21-
pass
2221

2322

2423
class EvalModeForLoadedModule(FileSetup):

test/distributed/_composable/test_replicate_with_compiler.py

-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ class MultiProcessInductorTestCase(MultiProcessTestCase, InductorTestCase):
7676
to handle isolation of the inductor cache dir.
7777
"""
7878

79-
pass
80-
8179

8280
class ReplicateTest(MultiProcessInductorTestCase):
8381
@property

test/distributed/elastic/rendezvous/rendezvous_backend_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class RendezvousBackendTestMixin(ABC):
2929
@abstractmethod
3030
def _corrupt_state(self) -> None:
3131
"""Corrupts the state stored in the backend."""
32-
pass
3332

3433
def _set_state(
3534
self, state: bytes, token: Optional[Any] = None

test/distributed/fsdp/test_fsdp_comm_hooks.py

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def custom_reduce_scatter(self, output, input, group=None):
9494
of a flattened tensor to all processes in a group.
9595
Currently a no-op.
9696
"""
97-
pass
9897

9998
def dummy_hook_for_sharded_fsdp(
10099
self, state: DummyState, grad: torch.Tensor, output: torch.Tensor

test/distributed/test_c10d_gloo.py

-1
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,6 @@ def tearDown(self):
21772177
os.remove(self.file.name)
21782178
except OSError as e:
21792179
print(str(e))
2180-
pass
21812180

21822181
@requires_gloo()
21832182
def test_single_dtype_single_bucket(self):

test/export/test_converter.py

-1
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,6 @@ def fuse_model(self):
13891389
torch.ao.quantization.fuse_modules(
13901390
self, [["conv2", "relu"]], inplace=True
13911391
)
1392-
pass
13931392

13941393
with override_quantized_engine("qnnpack"):
13951394
model = Standalone()

test/inductor/test_compiled_autograd.py

-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ def inner_compiler(gm_, example_inputs_):
416416
if is_bwd:
417417
# should be boxed inputs
418418
assert len(placeholders) == 1
419-
pass
420419
else:
421420
assert len(placeholders) > 1
422421

test/inductor/test_flex_attention.py

-1
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ def forward(a, mask):
11621162
def setup_context(ctx, inputs, output):
11631163
_, mask = inputs
11641164
ctx.mark_non_differentiable(mask)
1165-
pass
11661165

11671166
@staticmethod
11681167
def backward(ctx, i):

test/inductor/test_group_batch_fusion.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
has_fbgemm = True
2020
except Exception:
2121
has_fbgemm = False
22-
pass
2322

2423
requires_cuda = unittest.skipUnless(HAS_CUDA, "requires cuda")
2524

test/inductor/test_perf.py

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def TI(*size, mx=10, dtype=torch.int32, device=DEVICE):
8484

8585
class TestCase(InductorTestCase):
8686
device = DEVICE
87-
pass
8887

8988

9089
class NumBytesMetricTests(TestCase):

test/jit/test_backends.py

-5
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,16 @@ def test_execution(self):
114114
"""
115115
Stub for correctness tests.
116116
"""
117-
pass
118117

119118
def test_save_load(self):
120119
"""
121120
Stub for serialization tests.
122121
"""
123-
pass
124122

125123
def test_errors(self):
126124
"""
127125
Stub for testing error checking.
128126
"""
129-
pass
130127

131128

132129
class BasicModuleTest(JitBackendTestCase):
@@ -559,13 +556,11 @@ def test_execution(self):
559556
"""
560557
Stub for correctness tests.
561558
"""
562-
pass
563559

564560
def test_errors(self):
565561
"""
566562
Stub for testing error checking.
567563
"""
568-
pass
569564

570565

571566
class BasicModuleTestWithCompiler(JitBackendTestCaseWithCompiler):

test/jit/test_class_type.py

-1
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,6 @@ def __bool__(self):
962962
def test():
963963
if BadBool():
964964
print(1)
965-
pass
966965

967966
def test_init_compiled_first(self):
968967
@torch.jit.script # noqa: B903

test/jit/test_module_interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def forward(self, input):
160160
# type: (Tensor) -> Tensor
161161
r"""stuff 1"""
162162
r"""stuff 2"""
163-
pass
163+
pass # noqa: PIE790
164164
r"""stuff 3"""
165165

166166
class TestModule(nn.Module):

test/scripts/cuda_memcheck_common.py

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
class ParseError(Exception):
66
"""Whenever the simple parser is unable to parse the report, this exception will be raised"""
77

8-
pass
9-
108

119
class Report:
1210
"""A report is a container of errors, and a summary on how many errors are found"""

test/test_autograd.py

-3
Original file line numberDiff line numberDiff line change
@@ -12515,7 +12515,6 @@ def functional_op(x):
1251512515
)
1251612516
with self.assertRaisesRegex(RuntimeError, err_msg):
1251712517
out.add_(2)
12518-
pass
1251912518
else:
1252012519
out.add_(2)
1252112520

@@ -12611,7 +12610,6 @@ def run_test(fn):
1261112610
err_msg = "A view was created in inference mode and is being modified inplace"
1261212611
with self.assertRaisesRegex(RuntimeError, err_msg):
1261312612
fn(view_out)
12614-
pass
1261512613
else:
1261612614
fn(view_out)
1261712615

@@ -12632,7 +12630,6 @@ def run_test(fn):
1263212630
err_msg = "A view was created in inference mode and its base or another view "
1263312631
with self.assertRaisesRegex(RuntimeError, err_msg):
1263412632
view_out.grad_fn
12635-
pass
1263612633
else:
1263712634
view_out.grad_fn
1263812635

test/test_mobile_optimizer.py

-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ def forward(self, x):
427427

428428
def fuse_model(self):
429429
torch.ao.quantization.fuse_modules(self, [['conv2', 'relu']], inplace=True)
430-
pass
431430

432431
class Child(nn.Module):
433432
def __init__(self) -> None:

test/test_tensorexpr_pybind.py

-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ def test_kernel_shape_prop(self):
197197
# Graph doesn't have shape info for inputs => compilation should
198198
# fail
199199
exception_thrown = True
200-
pass
201200
assert exception_thrown
202201

203202
# Inject shape info and try compiling again
@@ -227,7 +226,6 @@ def forward(self, x, y):
227226
kernel = te.TensorExprKernel(graph)
228227
except RuntimeError:
229228
exception_thrown = True
230-
pass
231229
assert exception_thrown
232230

233231
# Try injecting shape info for graph inputs
@@ -239,7 +237,6 @@ def forward(self, x, y):
239237
except RuntimeError:
240238
# Graph has a 'self' argument for which we can't set shapes
241239
exception_thrown = True
242-
pass
243240
assert exception_thrown
244241

245242
# Remove 'self' argument and try annotating shapes one more time

test/test_testing.py

-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,6 @@ class UnexpectedException(Exception):
813813
the test should mock a component to raise this instead of the regular behavior. We avoid using a builtin
814814
exception here to avoid triggering possible handling of them.
815815
"""
816-
pass
817816

818817
@unittest.mock.patch("torch.testing._comparison.TensorLikePair.__init__", side_effect=UnexpectedException)
819818
def test_unexpected_error_originate(self, _):

tools/linter/adapters/flake8_linter.py

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ def _test_results_re() -> None:
132132
{'file': 'file.py', 'line': '8', 'column': '-10', 'code': 'W605',
133133
'message': "invalid escape sequence '/'"}
134134
"""
135-
pass
136135

137136

138137
def _run_command(

tools/testing/target_determination/heuristics/interface.py

-1
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,3 @@ def get_prediction_confidence(self, tests: list[str]) -> TestPrioritizations:
329329
positive means run, 0 means no idea, and magnitude = how confident the
330330
heuristic is. Used by AggregatedHeuristicsRankings.
331331
"""
332-
pass

torch/_awaits/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,3 @@ class _Await(torch._C._Await, Generic[W], metaclass=_PyAwaitMeta):
5151
In eager mode ``Await[W]`` can be used as ``W`` i.e. attributes of W can be called on ``Await[W]``,
5252
``_awaitable_wait()`` call will be transparently added.
5353
"""
54-
pass

torch/_dynamo/debug_utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,6 @@ def forward(self, primals_1: "f32[1001, 6]", primals_2: "f32[s0]", primals_3: "S
719719

720720
class TensorContainer:
721721
"Container for tensors as attributes"
722-
pass
723722

724723
# Dictionary for tensors from annotations
725724
kwargs: Dict[str, Any] = {}

torch/_dynamo/decorators.py

-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def fn(a):
142142
@_disallow_in_graph_helper(throw_if_not_allowed=False)
143143
def graph_break():
144144
"""Force a graph break"""
145-
pass
146145

147146

148147
def forbid_in_graph(fn):
@@ -348,7 +347,6 @@ def _allow_in_graph_einops():
348347
)
349348

350349
# einops > 0.6.1 will call the op registration logic as it is imported.
351-
pass
352350
except ImportError:
353351
# einops <= 0.6.1
354352
allow_in_graph(einops.rearrange)

torch/_dynamo/repro/after_aot.py

-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ def dump_compiler_graph_state(gm, args, compiler_name, *, accuracy=None):
323323
BuckTargetWriter(file_name).write()
324324
except OSError:
325325
log.warning("No write permissions for %s", repro_path)
326-
pass
327326

328327

329328
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

torch/_dynamo/variables/builder.py

-1
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,6 @@ def wrap_numpy_ndarray(self, value):
15431543
# One can not easily make nditer elements writable,
15441544
# but warning is not the end of the world
15451545
assert isinstance(value.base, np.nditer)
1546-
pass
15471546

15481547
try:
15491548
tensor_value = _util._try_convert_to_tensor(value)

torch/_dynamo/variables/dicts.py

-2
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,6 @@ class DataClassVariable(ConstDictVariable):
657657
Keeping since we wish to support dataclasses in general in the future
658658
"""
659659

660-
pass
661-
662660

663661
class CustomizedDictVariable(ConstDictVariable):
664662
@staticmethod

torch/_dynamo/variables/misc.py

-2
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,6 @@ def reconstruct(self, codegen):
423423
class InspectParameterVariable(VariableTracker):
424424
"""This is not implemented, if used will graph break."""
425425

426-
pass
427-
428426

429427
class InspectBoundArgumentsVariable(VariableTracker):
430428
"""represents inspect.signature(...).bind(...)"""

torch/_export/passes/replace_with_hop_pass_util.py

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def set_hoo_node_meta(call_func_node):
6868
output_node = output_args[idx]
6969
get_item_node._rename(output_node.name)
7070
get_item_node.meta = output_node.meta
71-
pass
7271

7372
elif isinstance(output_args, torch.fx.Node):
7473
call_func_node = graph.create_node(

torch/_export/verifier.py

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ def check_additional(self, gm: GraphModule) -> None:
149149
"""
150150
Additional checks that are specific to some dialects.
151151
"""
152-
pass
153152

154153
@final
155154
def check(self, ep: "ExportedProgram") -> None:

torch/_functorch/_aot_autograd/autograd_cache.py

-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ class CompiledForward(FXGraphCacheLoadable):
275275
Cacheable entry for a forward function
276276
"""
277277

278-
pass
279-
280278

281279
@dataclass
282280
class CompiledBackward(FXGraphCacheLoadable):

torch/_inductor/autoheuristic/autoheuristic.py

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ class InconsistentMetadata(Exception):
4242
not match the metadata it would store if the file didn't exist.
4343
"""
4444

45-
pass
46-
4745

4846
class AutoHeuristic:
4947
"""

torch/_inductor/codecache.py

-2
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,6 @@ class BypassFxGraphCache(Exception):
708708
Exception to indicate that the FxGraphCache should be bypassed.
709709
"""
710710

711-
pass
712-
713711

714712
class FxGraphHashDetails:
715713
"""

torch/_inductor/codegen/simd.py

-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ def finalize_indexing(self, indices: Sequence[sympy.Expr]):
397397
Hook called right before codegen with every index that will be
398398
used in the fused kernel.
399399
"""
400-
pass
401400

402401
def store_reduction(self, name: str, index: sympy.Expr, value: CSEVariable):
403402
prior = self.inside_reduction

torch/_inductor/codegen/wrapper.py

-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ def plan(self, state: MemoryPlanningState) -> MemoryPlanningLine:
358358

359359
def codegen(self, code: IndentedBuffer) -> None:
360360
"""Second pass to output code"""
361-
pass
362361

363362
def __str__(self) -> str:
364363
"""

torch/_inductor/cudagraph_trees.py

-2
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ class OutputAliasInfo:
720720

721721
class _UnaliasedStorage(OutputAliasInfo):
722722
"Singleton to mark that the graph output constructs a new alias or is None"
723-
pass
724723

725724

726725
UnaliasedStorage = _UnaliasedStorage()
@@ -1546,7 +1545,6 @@ def remove_path_cached_tensors(self) -> None:
15461545
def clear_path_state(self) -> None:
15471546
"Clear the path state in this current executing node"
15481547
# this doesnt actually do anything right now, leaving it as placeholder
1549-
pass
15501548

15511549
@staticmethod
15521550
def _tensor_metadata(

0 commit comments

Comments
 (0)