Repository navigation
[release/2.15] Keep ruff targeting Python 3.10 until the 3.10 code is removed - #202303
Conversation
… removed Follow-up to pytorch#202273. Ruff takes its target version from requires-python; at >=3.11 it enables UP035, UP036, UP044, UP017 and UP041 and flags 257 places in 162 files that still carry Python 3.10 compatibility code, so the Lint job fails on release/2.15. Pin target-version to py310 so lint is unchanged. Same change as the pin added to pytorch#202271 on main.
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Findings (1): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202303
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit f48bacd with merge base 2cce586 ( 🟡 GREEN LIGHT - PR requires human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Automated review of f48bacd: nothing blocking; ready for human review.
The PR adds target-version = "py310" to \[tool.ruff\] in pyproject.toml on release/2.15. Ruff had started inferring its target from requires-python = ">=3.11", which turned on pyupgrade rules that fail across about 160 files; the pin stops that. Recommendation: Approve, with one minor fix to the new comment.
⚪ 1 non-blocking finding
Line 498 in f48bacd
The new comment (lines 498-501) is the only note in the tree saying when to remove the pin, and it doesn't point to the cleanup it depends on. Problems: (1) Incomplete rule list: it names UP035/UP036/UP044/UP017 but leaves out UP041, which the PR description lists among the failures. (2) Stale number: "~160 files" will be wrong as soon as # 199417 makes progress. (3) No issue reference: "until that code is removed, then delete this" doesn't name # 199417, so whoever finishes the 3.10 cleanup has nothing to search for and the pin can quietly outlive it. (4) Inconsistent with the file: the other 3.10 leftover here uses a TODO marker (# TODO: Remove Python-3.10 specific suppressions above B905, line 573), so without one this pin won't turn up in a search for 3.10 TODOs. Fix: use something like # TODO(\# 199417): remove once the Python 3.10 compatibility code is gone; until then ruff would infer py311 from requires-python and enable UP017/UP035/UP036/UP041/UP044.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
) Go through the following checklist - [x] Passes lint (checked `ruff` and the PYFMT adapter directly, not through `lintrunner`) - [ ] Added/updated tests - [ ] Updated documentation (if applicable) - [ ] Included benchmark results (for PRs impacting perf) --- ## Linked issue or supporting maintainer Follow-up to #202271 / #202273, which raised `requires-python` to `>=3.11` and (via #202303 on `release/2.15`) pinned ruff to 3.10 until this cleanup. ## BC-breaking? No. Lint configuration and Python 3.11-only syntax/imports only. Behaviour is unchanged: the rewritten `sys.version_info >= (3, 11)` branches were already the live ones. ## Summary (human written only) Removes `target-version = "py310"` from `[tool.ruff]` so ruff takes its target from `requires-python` (3.11) again, and applies the findings that turns on. ## Agent details (if applicable) Drafted with Claude Code; diff reviewed by hand. The commit message follows. Without the pin, `ruff check .` (ruff 0.14.4, the version lintrunner pins) goes from 941 to 1115 findings: 174 new, in 143 files, from five rules. | Rule | Count | What | Fix | |---|---|---|---| | UP035 | 103 | `typing_extensions` imports that are in `typing` / `collections.abc` on 3.11 | safe | | UP044 | 30 | `Unpack[...]` | unsafe | | UP017 | 20 | `timezone.utc` -> `UTC` | safe | | UP036 | 19 | obsolete `sys.version_info` checks | unsafe | | UP041 | 2 | aliased errors | safe | Changes: - Delete the pin. - `ruff check --fix --unsafe-fixes` for those five rules. I read the UP036 rewrites (e.g. `torch/_inductor/await_utils.py`, the `bisect_left` paths in `torch/fx/proxy.py` and `symbolic_shapes.py`); each keeps the 3.11 branch. - Clean up what the fixes leave behind (27 unused imports and similar, all safe fixes), then `usort` + `ruff format` on the 94 files where moving imports changed their order. One `import tomllib` in `test/spincli/test_spin.py` was left out of order and is moved by hand. - Python 3.11 across the lint tooling, instead of carving out the adapters. lintrunner runs 15 adapters with `uv run --python 3.10`, where the autofix's `import tomllib` and `typing.Self` would not exist. Rather than pin them to a 3.10 ruff target, the second commit moves those 15 `--python 3.10` entries in `.lintrunner.toml` and their `requires-python` script headers to 3.11, drops the `tomli ; python_version < '3.11'` dependency markers, and applies the same fixes to `tools/linter/adapters/**`. `mypy-strict.ini` moves from `python_version = 3.10` to 3.11 too. Not changed: `pyrefly.toml` (`python-version = "3.12"`), and the `B905` entry in `[tool.ruff.lint] ignore`, whose comment says "TODO: Remove Python-3.10 specific suppressions". I did not check what removing it would change; it is a separate cleanup. This touches 161 files (+294/-427) across `torch/`, `torchgen/`, `test/`, `.github/scripts` and `tools`, so it will conflict with in-flight PRs; the sooner it lands the fewer rebases. ## Testing With `ruff==0.14.4` and the repo config, on the tree at this PR's base: - Before the change (pin in place): 941 findings. - With the pin removed and no fixes: 1115 findings (174 new). - This PR: 939 findings, none beyond the 941 baseline. - `pyfmt_linter.py` (usort + ruff format) on the changed `.py` files introduces nothing new; it flags only `torch/utils/checkpoint.py`, which it also flags without this change. - Smoke-tested under `uv run --python 3.11 --script`: `pyfmt_linter`, `pyproject_linter` and `cmake_minimum_required_linter` (clean on `pyproject.toml`), and `license_files_linter` starts. The other moved adapters were not run individually. - All 139 changed `.py`/`.pyi` files parse on CPython 3.11. Not run: `lintrunner` end to end, `mypy --config-file mypy-strict.ini` on 3.11 (used by `test/test_type_hints.py`), and the test suites. CI is the verification for those. Authored with an AI assistant; the diff was reviewed by hand. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: #203051 Approved by: https://github.com/williamwen42, https://github.com/justinchuby, https://github.com/d4l3k
…rch#203051) Go through the following checklist - [x] Passes lint (checked `ruff` and the PYFMT adapter directly, not through `lintrunner`) - [ ] Added/updated tests - [ ] Updated documentation (if applicable) - [ ] Included benchmark results (for PRs impacting perf) --- ## Linked issue or supporting maintainer Follow-up to pytorch#202271 / pytorch#202273, which raised `requires-python` to `>=3.11` and (via pytorch#202303 on `release/2.15`) pinned ruff to 3.10 until this cleanup. ## BC-breaking? No. Lint configuration and Python 3.11-only syntax/imports only. Behaviour is unchanged: the rewritten `sys.version_info >= (3, 11)` branches were already the live ones. ## Summary (human written only) Removes `target-version = "py310"` from `[tool.ruff]` so ruff takes its target from `requires-python` (3.11) again, and applies the findings that turns on. ## Agent details (if applicable) Drafted with Claude Code; diff reviewed by hand. The commit message follows. Without the pin, `ruff check .` (ruff 0.14.4, the version lintrunner pins) goes from 941 to 1115 findings: 174 new, in 143 files, from five rules. | Rule | Count | What | Fix | |---|---|---|---| | UP035 | 103 | `typing_extensions` imports that are in `typing` / `collections.abc` on 3.11 | safe | | UP044 | 30 | `Unpack[...]` | unsafe | | UP017 | 20 | `timezone.utc` -> `UTC` | safe | | UP036 | 19 | obsolete `sys.version_info` checks | unsafe | | UP041 | 2 | aliased errors | safe | Changes: - Delete the pin. - `ruff check --fix --unsafe-fixes` for those five rules. I read the UP036 rewrites (e.g. `torch/_inductor/await_utils.py`, the `bisect_left` paths in `torch/fx/proxy.py` and `symbolic_shapes.py`); each keeps the 3.11 branch. - Clean up what the fixes leave behind (27 unused imports and similar, all safe fixes), then `usort` + `ruff format` on the 94 files where moving imports changed their order. One `import tomllib` in `test/spincli/test_spin.py` was left out of order and is moved by hand. - Python 3.11 across the lint tooling, instead of carving out the adapters. lintrunner runs 15 adapters with `uv run --python 3.10`, where the autofix's `import tomllib` and `typing.Self` would not exist. Rather than pin them to a 3.10 ruff target, the second commit moves those 15 `--python 3.10` entries in `.lintrunner.toml` and their `requires-python` script headers to 3.11, drops the `tomli ; python_version < '3.11'` dependency markers, and applies the same fixes to `tools/linter/adapters/**`. `mypy-strict.ini` moves from `python_version = 3.10` to 3.11 too. Not changed: `pyrefly.toml` (`python-version = "3.12"`), and the `B905` entry in `[tool.ruff.lint] ignore`, whose comment says "TODO: Remove Python-3.10 specific suppressions". I did not check what removing it would change; it is a separate cleanup. This touches 161 files (+294/-427) across `torch/`, `torchgen/`, `test/`, `.github/scripts` and `tools`, so it will conflict with in-flight PRs; the sooner it lands the fewer rebases. ## Testing With `ruff==0.14.4` and the repo config, on the tree at this PR's base: - Before the change (pin in place): 941 findings. - With the pin removed and no fixes: 1115 findings (174 new). - This PR: 939 findings, none beyond the 941 baseline. - `pyfmt_linter.py` (usort + ruff format) on the changed `.py` files introduces nothing new; it flags only `torch/utils/checkpoint.py`, which it also flags without this change. - Smoke-tested under `uv run --python 3.11 --script`: `pyfmt_linter`, `pyproject_linter` and `cmake_minimum_required_linter` (clean on `pyproject.toml`), and `license_files_linter` starts. The other moved adapters were not run individually. - All 139 changed `.py`/`.pyi` files parse on CPython 3.11. Not run: `lintrunner` end to end, `mypy --config-file mypy-strict.ini` on 3.11 (used by `test/test_type_hints.py`), and the test suites. CI is the verification for those. Authored with an AI assistant; the diff was reviewed by hand. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#203051 Approved by: https://github.com/williamwen42, https://github.com/justinchuby, https://github.com/d4l3k
…rch#203051) Go through the following checklist - [x] Passes lint (checked `ruff` and the PYFMT adapter directly, not through `lintrunner`) - [ ] Added/updated tests - [ ] Updated documentation (if applicable) - [ ] Included benchmark results (for PRs impacting perf) --- ## Linked issue or supporting maintainer Follow-up to pytorch#202271 / pytorch#202273, which raised `requires-python` to `>=3.11` and (via pytorch#202303 on `release/2.15`) pinned ruff to 3.10 until this cleanup. ## BC-breaking? No. Lint configuration and Python 3.11-only syntax/imports only. Behaviour is unchanged: the rewritten `sys.version_info >= (3, 11)` branches were already the live ones. ## Summary (human written only) Removes `target-version = "py310"` from `[tool.ruff]` so ruff takes its target from `requires-python` (3.11) again, and applies the findings that turns on. ## Agent details (if applicable) Drafted with Claude Code; diff reviewed by hand. The commit message follows. Without the pin, `ruff check .` (ruff 0.14.4, the version lintrunner pins) goes from 941 to 1115 findings: 174 new, in 143 files, from five rules. | Rule | Count | What | Fix | |---|---|---|---| | UP035 | 103 | `typing_extensions` imports that are in `typing` / `collections.abc` on 3.11 | safe | | UP044 | 30 | `Unpack[...]` | unsafe | | UP017 | 20 | `timezone.utc` -> `UTC` | safe | | UP036 | 19 | obsolete `sys.version_info` checks | unsafe | | UP041 | 2 | aliased errors | safe | Changes: - Delete the pin. - `ruff check --fix --unsafe-fixes` for those five rules. I read the UP036 rewrites (e.g. `torch/_inductor/await_utils.py`, the `bisect_left` paths in `torch/fx/proxy.py` and `symbolic_shapes.py`); each keeps the 3.11 branch. - Clean up what the fixes leave behind (27 unused imports and similar, all safe fixes), then `usort` + `ruff format` on the 94 files where moving imports changed their order. One `import tomllib` in `test/spincli/test_spin.py` was left out of order and is moved by hand. - Python 3.11 across the lint tooling, instead of carving out the adapters. lintrunner runs 15 adapters with `uv run --python 3.10`, where the autofix's `import tomllib` and `typing.Self` would not exist. Rather than pin them to a 3.10 ruff target, the second commit moves those 15 `--python 3.10` entries in `.lintrunner.toml` and their `requires-python` script headers to 3.11, drops the `tomli ; python_version < '3.11'` dependency markers, and applies the same fixes to `tools/linter/adapters/**`. `mypy-strict.ini` moves from `python_version = 3.10` to 3.11 too. Not changed: `pyrefly.toml` (`python-version = "3.12"`), and the `B905` entry in `[tool.ruff.lint] ignore`, whose comment says "TODO: Remove Python-3.10 specific suppressions". I did not check what removing it would change; it is a separate cleanup. This touches 161 files (+294/-427) across `torch/`, `torchgen/`, `test/`, `.github/scripts` and `tools`, so it will conflict with in-flight PRs; the sooner it lands the fewer rebases. ## Testing With `ruff==0.14.4` and the repo config, on the tree at this PR's base: - Before the change (pin in place): 941 findings. - With the pin removed and no fixes: 1115 findings (174 new). - This PR: 939 findings, none beyond the 941 baseline. - `pyfmt_linter.py` (usort + ruff format) on the changed `.py` files introduces nothing new; it flags only `torch/utils/checkpoint.py`, which it also flags without this change. - Smoke-tested under `uv run --python 3.11 --script`: `pyfmt_linter`, `pyproject_linter` and `cmake_minimum_required_linter` (clean on `pyproject.toml`), and `license_files_linter` starts. The other moved adapters were not run individually. - All 139 changed `.py`/`.pyi` files parse on CPython 3.11. Not run: `lintrunner` end to end, `mypy --config-file mypy-strict.ini` on 3.11 (used by `test/test_type_hints.py`), and the test suites. CI is the verification for those. Authored with an AI assistant; the diff was reviewed by hand. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#203051 Approved by: https://github.com/williamwen42, https://github.com/justinchuby, https://github.com/d4l3k
Fixes the
Lintjob onrelease/2.15, which has failed since #202273 landed (failing run). The same pin is part of #202271 on main.Summary
Add
target-version = "py310"to[tool.ruff]inpyproject.toml.Why
Ruff takes its target version from
requires-pythonwhentarget-versionis not set. #202273 raisedrequires-pythonto>=3.11, so ruff started linting for 3.11 and enabled the pyupgrade rules for it. Thelintrunner-noclang-alljob now reports 257 findings in 162 files that still carry Python 3.10 compatibility code:sys.version_infocheckstyping_extensionsimports that are intypingon 3.11Unpack[...]timezone.utcThe previous commit on the branch (
30c000d9a) had none of these. On a PR, lintrunner only checks the changed files, which is why #202273's own Lint run passed; the push run lints every file.I did not apply the autofixes: 134 of them need
--unsafe-fixes, and the Python 3.10 cleanup (#199417) is rewriting the sametorch/_dynamofiles. The pin keeps linting at 3.10 until that code is removed; delete it then.Testing
With
ruff==0.14.4and the repo config, on the 162 files from the failing run:ruff checkpasses on all 162 files, andruff format --checkflags onlytorch/utils/checkpoint.py, which it also flags at30c000d9a.Not run through lintrunner in CI.