From 7a08755c5f3630150c50d09e16c0abf9501dea1e Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Fri, 11 Jul 2025 15:16:20 +0000 Subject: [PATCH] [BE][Ez]: Update ruff to 0.12.2 (#157937) Updates to the latest version of ruff and apply some fixes that it flagged and silence a few new lints Pull Request resolved: https://github.com/pytorch/pytorch/pull/157937 Approved by: https://github.com/ezyang --- .lintrunner.toml | 4 ++-- pyproject.toml | 6 ++++++ test/quantization/fx/test_quantize_fx.py | 4 ++-- torch/_inductor/select_algorithm.py | 9 ++++++--- torch/package/_stdlib.py | 4 ++-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.lintrunner.toml b/.lintrunner.toml index 6b24f3a9d65f..ef141907068c 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -1462,7 +1462,7 @@ init_command = [ 'black==23.12.1', 'usort==1.0.8.post1', 'isort==6.0.1', - 'ruff==0.11.13', # sync with RUFF + 'ruff==0.12.2', # sync with RUFF ] is_formatter = true @@ -1597,7 +1597,7 @@ init_command = [ 'python3', 'tools/linter/adapters/pip_init.py', '--dry-run={{DRYRUN}}', - 'ruff==0.11.13', # sync with PYFMT + 'ruff==0.12.2', # sync with PYFMT ] is_formatter = true diff --git a/pyproject.toml b/pyproject.toml index b63ff1a385b1..c8b154a4e6e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -130,6 +130,7 @@ ignore = [ "E741", "EXE001", "F405", + "FURB122", # writelines # these ignores are from flake8-logging-format; please fix! "G101", # these ignores are from ruff NPY; please fix! @@ -152,6 +153,7 @@ ignore = [ "SIM117", "SIM118", "UP007", # keep-runtime-typing + "UP045", # keep-runtime-typing "TC006", ] select = [ @@ -233,6 +235,10 @@ select = [ "YTT", ] +[tool.ruff.lint.pyupgrade] +# Preserve types, even if a file imports `from __future__ import annotations`. +keep-runtime-typing = true + [tool.ruff.lint.per-file-ignores] "__init__.py" = [ "F401", diff --git a/test/quantization/fx/test_quantize_fx.py b/test/quantization/fx/test_quantize_fx.py index 2569e2f7e4ce..359767f3997b 100644 --- a/test/quantization/fx/test_quantize_fx.py +++ b/test/quantization/fx/test_quantize_fx.py @@ -6648,7 +6648,7 @@ class TestQuantizeFx(QuantizationTestCase): """ def __init__(self, input_dim, output_dim): - super(__class__, self).__init__() + super().__init__() self.w = nn.Parameter(torch.randn(input_dim, output_dim)) self.b = nn.Parameter(torch.randn(input_dim)) @@ -6661,7 +6661,7 @@ class TestQuantizeFx(QuantizationTestCase): """ def __init__(self, input_dim, hidden_dim, output_dim): - super(__class__, self).__init__() + super().__init__() self.submodule_1 = SubModule(hidden_dim, input_dim) setattr(self, 'submodule|2', SubModule(hidden_dim, hidden_dim)) setattr(self, 'submodule/3', SubModule(hidden_dim, hidden_dim)) diff --git a/torch/_inductor/select_algorithm.py b/torch/_inductor/select_algorithm.py index ea3537b2a1ce..9e3facdad75c 100644 --- a/torch/_inductor/select_algorithm.py +++ b/torch/_inductor/select_algorithm.py @@ -2597,11 +2597,14 @@ class AlgorithmSelectorCache(PersistentCache): "Exception %s for benchmark choice %s", e, futures[future], - exc_info=True, + exc_info=e, ) else: - log.error( - "Exception %s for benchmark choice %s", e, futures[future] + log.exception( # noqa: G202 + "Exception %s for benchmark choice %s", + e, + futures[future], + exc_info=e, ) else: counters["inductor"]["select_algorithm_num_precompiles"] += 1 diff --git a/torch/package/_stdlib.py b/torch/package/_stdlib.py index 1f5e1636c95b..57a51ac41cfd 100644 --- a/torch/package/_stdlib.py +++ b/torch/package/_stdlib.py @@ -17,12 +17,12 @@ def is_stdlib_module(module: str) -> bool: def _get_stdlib_modules(): - if sys.version_info.major == 3: + if sys.version_info.major == 3: # noqa: UP036 if sys.version_info.minor == 9: return stdlib3_9 if sys.version_info.minor >= 10: # noqa: YTT204 return sys.stdlib_module_names # type: ignore[attr-defined] - elif sys.version_info.major > 3: + elif sys.version_info.major > 3: # noqa: UP036 return sys.stdlib_module_names # type: ignore[attr-defined] raise RuntimeError(f"Unsupported Python version: {sys.version_info}")