From b8194268a6fbc369cce413990826492d36d88bdc Mon Sep 17 00:00:00 2001 From: Yuanyuan Chen Date: Sat, 18 Oct 2025 04:52:41 +0000 Subject: [PATCH] Remove unnecessary noqa suppressions (#164106) This PR removes unused `noqa` suppressions in Python code. Pull Request resolved: https://github.com/pytorch/pytorch/pull/164106 Approved by: https://github.com/albanD --- torch/_inductor/fuzzer.py | 8 ++++---- torch/_logging/_internal.py | 2 +- torch/nn/intrinsic/qat/modules/conv_fused.py | 1 - torch/nn/intrinsic/qat/modules/linear_fused.py | 1 - torch/nn/intrinsic/qat/modules/linear_relu.py | 1 - torch/nn/modules/pooling.py | 2 +- torch/nn/parallel/distributed.py | 2 +- torch/nn/utils/_named_member_accessor.py | 2 +- torch/utils/_triton.py | 2 +- 9 files changed, 9 insertions(+), 12 deletions(-) diff --git a/torch/_inductor/fuzzer.py b/torch/_inductor/fuzzer.py index 403e1c2eca9e..55e49b61f7c7 100644 --- a/torch/_inductor/fuzzer.py +++ b/torch/_inductor/fuzzer.py @@ -310,7 +310,7 @@ class SamplingMethod(Enum): ) try: new_default = new_type() - except Exception: # noqa: E722 + except Exception: # if default constructor doesn't work, try None new_default = None @@ -779,7 +779,7 @@ class ConfigFuzzer: test_model_fn = self.test_model_fn_factory() try: test_model_fn() - except Exception as exc: # noqa: E722 + except Exception as exc: return handle_return( "Eager exception", Status.FAILED_RUN_EAGER_EXCEPTION, True, exc ) @@ -788,7 +788,7 @@ class ConfigFuzzer: try: test_model_fn2 = self.test_model_fn_factory() comp = torch.compile(test_model_fn2, backend="inductor") - except Exception as exc: # noqa: E722 + except Exception as exc: return handle_return( "Exception compiling", Status.FAILED_COMPILE, True, exc ) @@ -796,7 +796,7 @@ class ConfigFuzzer: # try running compiled try: compile_result = comp() - except Exception as exc: # noqa: E722 + except Exception as exc: return handle_return( "Exception running compiled", Status.FAILED_RUN_COMPILE_EXCEPTION, diff --git a/torch/_logging/_internal.py b/torch/_logging/_internal.py index 87fe5836b147..a84268610263 100644 --- a/torch/_logging/_internal.py +++ b/torch/_logging/_internal.py @@ -699,7 +699,7 @@ Examples: TORCH_LOGS_OUT=/tmp/output.txt will output the logs to /tmp/output.txt as well. This is useful when the output is long. -""" # flake8: noqa: B950 +""" msg = f""" TORCH_LOGS Info {examples} diff --git a/torch/nn/intrinsic/qat/modules/conv_fused.py b/torch/nn/intrinsic/qat/modules/conv_fused.py index 79c7dc116a67..f8dc1d49aad3 100644 --- a/torch/nn/intrinsic/qat/modules/conv_fused.py +++ b/torch/nn/intrinsic/qat/modules/conv_fused.py @@ -1,4 +1,3 @@ -# flake8: noqa: F401 r"""Intrinsic QAT Modules. This file is in the process of migration to `torch/ao/nn/intrinsic/qat`, and diff --git a/torch/nn/intrinsic/qat/modules/linear_fused.py b/torch/nn/intrinsic/qat/modules/linear_fused.py index 2c961557daff..79567d67bd1f 100644 --- a/torch/nn/intrinsic/qat/modules/linear_fused.py +++ b/torch/nn/intrinsic/qat/modules/linear_fused.py @@ -1,4 +1,3 @@ -# flake8: noqa: F401 r"""Intrinsic QAT Modules. This file is in the process of migration to `torch/ao/nn/intrinsic/qat`, and diff --git a/torch/nn/intrinsic/qat/modules/linear_relu.py b/torch/nn/intrinsic/qat/modules/linear_relu.py index 1b9fad39f646..71705320075e 100644 --- a/torch/nn/intrinsic/qat/modules/linear_relu.py +++ b/torch/nn/intrinsic/qat/modules/linear_relu.py @@ -1,4 +1,3 @@ -# flake8: noqa: F401 r"""Intrinsic QAT Modules. This file is in the process of migration to `torch/ao/nn/intrinsic/qat`, and diff --git a/torch/nn/modules/pooling.py b/torch/nn/modules/pooling.py index ed270a812eaf..777e6b0abd8c 100644 --- a/torch/nn/modules/pooling.py +++ b/torch/nn/modules/pooling.py @@ -298,7 +298,7 @@ class MaxPool3d(_MaxPoolNd): .. _link: https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md - """ # noqa: E501 + """ kernel_size: _size_3_t stride: _size_3_t diff --git a/torch/nn/parallel/distributed.py b/torch/nn/parallel/distributed.py index d630771d6e8f..3436a97400ff 100644 --- a/torch/nn/parallel/distributed.py +++ b/torch/nn/parallel/distributed.py @@ -775,7 +775,7 @@ class DistributedDataParallel(Module, Joinable): "DistributedDataParallel device_ids and output_device arguments " "only work with single-device/multiple-device GPU modules or CPU modules, " f"but got device_ids {device_ids}, output_device {output_device}, " - f"and module parameters { ({p.device for p in self._module_parameters}) }.", # noqa: E201,E202 + f"and module parameters { ({p.device for p in self._module_parameters}) }.", ) self.device_ids = None diff --git a/torch/nn/utils/_named_member_accessor.py b/torch/nn/utils/_named_member_accessor.py index 7178b11d00d8..111a24ec1863 100644 --- a/torch/nn/utils/_named_member_accessor.py +++ b/torch/nn/utils/_named_member_accessor.py @@ -146,7 +146,7 @@ class NamedMemberAccessor: f"{module._get_name()} has no attribute `{attr}`" ) from ex if not isinstance(submodule, torch.nn.Module): - raise TypeError( # noqa: B904 + raise TypeError( f"submodule `{name}`: {submodule} is not an instance of torch.nn.Module" ) self.memo[name] = submodule diff --git a/torch/utils/_triton.py b/torch/utils/_triton.py index 5f0ca5b4eff8..f062f7e7508c 100644 --- a/torch/utils/_triton.py +++ b/torch/utils/_triton.py @@ -16,7 +16,7 @@ def has_triton_package() -> bool: @functools.cache def get_triton_version(fallback: tuple[int, int] = (0, 0)) -> tuple[int, int]: try: - import triton # noqa: F401 + import triton major, minor = tuple(int(v) for v in triton.__version__.split(".")[:2]) return (major, minor)