Skip to content

[release/2.15] Keep ruff targeting Python 3.10 until the 3.10 code is removed - #202303

Merged
atalman merged 1 commit into
pytorch:release/2.15from
atalman:ruff_py310_pin_r215
Oct 28, 2026
Merged

atalman merged 1 commit into
pytorch:release/2.15from
atalman:ruff_py310_pin_r215

Conversation

@atalman

@atalman atalman commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Fixes the Lint job on release/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] in pyproject.toml.

Why

Ruff takes its target version from requires-python when target-version is not set. #202273 raised requires-python to >=3.11, so ruff started linting for 3.11 and enabled the pyupgrade rules for it. The lintrunner-noclang-all job now reports 257 findings in 162 files that still carry Python 3.10 compatibility code:

Rule Count What
UP036 106 obsolete sys.version_info checks
UP035 101 typing_extensions imports that are in typing on 3.11
UP044 30 Unpack[...]
UP017 20 timezone.utc
UP041 2 aliased errors

The 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 same torch/_dynamo files. The pin keeps linting at 3.10 until that code is removed; delete it then.

Testing

With ruff==0.14.4 and the repo config, on the 162 files from the failing run:

  • Before: 257 findings (the counts above).
  • After the pin: ruff check passes on all 162 files, and ruff format --check flags only torch/utils/checkpoint.py, which it also flags at 30c000d9a.

Not run through lintrunner in CI.

… 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.
@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Oct 27, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - 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.

Findings (1):

[minor] pyproject.toml:498
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.`

Reviewed commit: f48bacd

Review run

🔗 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 Failures

As of commit f48bacd with merge base 2cce586 (image):
💚 Looks good so far! There are no failures yet. 💚

🟡 GREEN LIGHT - PR requires human review:

  • CI gate configuration
    • Adds target-version = "py310" under [tool.ruff] in pyproject.toml, overriding requires-python = ">=3.11" for the gate
    • .lintrunner.toml runs tools/linter/adapters/ruff_linter.py --config=pyproject.toml, so this retargets the merge-blocking ruff lint and ruff format
  • Signal suppressed rather than fixed
    • Pin silences the UP035/UP036/UP044/UP017 findings on 3.10-compat code instead of fixing them, which is a judgment call for a human
    • Pinning the version also changes every other version-gated ruff rule and formatter decision, not only the UP rules named
  • Socialization
    • Targets release/2.15, and the same pin is still pending in #​202271 on main, so release managers should see this branch-only lint change

reason: not_trivial
Reviewed commit: f48bacd

Inference job

🐛 Report a wrong verdict

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorchgreenlight pytorchgreenlight Bot added the GL/human GreenLight marked as needing human review label Oct 27, 2026
@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Oct 27, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

# Ruff takes its target version from requires-python, which is now >=3.11. That

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.

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Oct 27, 2026
@atalman
atalman merged commit 31a77fc into pytorch:release/2.15 Oct 28, 2026
174 checks passed
pytorchmergebot pushed a commit that referenced this pull request Nov 3, 2026
)

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
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…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
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GL/human GreenLight marked as needing human review ready for review Automated review passed, ready for a final review by a maintainer. topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants