Repository navigation
Refactor: Enable ruff's Python 3.11 upgrade rules - #293
ModeSevenIndustrialSolutions merged 2 commits into
Conversation
Python 3.10 is end of life and the package already requires 3.11, so replace typing.List/Dict/Tuple with builtin generics, Union/Optional with X | Y, and typing.Callable/Sequence with collections.abc imports. Every edit here comes from `ruff check --fix` (UP006, UP007, UP035, then F401/I001 to drop the now-unused typing names and sort imports) and `ruff format`. Annotations and imports only; no behaviour change. The typings/nss stubs that symlink into src/ pick up the same fixes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
The package requires Python 3.11 and ruff targets py311, so the ignores kept "for Python 3.10 compatibility" no longer protect anything. Remove them so ruff keeps the annotations modern. test/setup_certs.py keeps UP006 and UP035 as a per-file ignore: it is an executable file this change could not edit. Converting its two List/Tuple annotations and dropping that ignore is a follow-up. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the Python 3.11 annotation modernization and Ruff upgrade-rule changes.
No open issues 🎉
What changed in this PR
Modernizes type annotations to match the package’s Python 3.11 minimum and enables Ruff’s upgrade rules, addressing #291 without changing runtime logic.
Changes:
- Replaces legacy
typingcollections and unions with built-in generics and|syntax. - Moves
CallableandSequenceimports tocollections.abc. - Enables
UP006,UP007, andUP035, retaining a documented temporary exception fortest/setup_certs.py.
| File | Description |
|---|---|
typings/nss/error.pyi |
Uses built-in list and tuple annotations. |
test/exceptions.py |
Imports Sequence from collections.abc. |
src/ssl.pyi |
Modernizes tuple, union, and callable annotations/imports. |
src/nss.pyi |
Modernizes collection, union, and callable annotations/imports. |
src/io.pyi |
Uses built-in collections and ` |
src/deprecations.py |
Replaces typing.Dict with dict. |
pyproject.toml |
Enables upgrade rules with a temporary per-file exception. |
import_files.py |
Uses built-in list annotations for copy statistics. |
Review effort: Balanced
There was a problem hiding this comment.
🤖 Antagonistic review by agent: no line-level findings; the summary below is the verdict.
The annotation modernization is consistent with the existing Python 3.11 minimum and preserves the declared types. No actionable defects found; the remaining certificate-setup lint exception is narrow and explicitly documented.
Antagonistic round 1 of 3.
Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.
ef0f620
into
lfreleng-actions:main
Closes #291
Authored by an AI agent; human review required
claude-opus-5.5via GitHub Copilot CLI1ec99106a58981dabe2f549c00235d73f7df5568uvx ruff@0.17.4 check src test scripts typings import_files.pyuvx ruff@0.17.4 format --check src test scripts typings import_files.pyprek run --files <changed files>uv run --no-sync mypy src/*.pyi --ignore-missing-importsuv sync --all-extrasuv pip install --no-build-isolation -e .uv run --no-sync pytest -q -p no:cacheprovideraislop scan --changes --jsongit log --raw --format=%h 1ec99106a58981dabe2f549c00235d73f7df5568..HEADThe
github-code-monkey-botworkflow opened this pull request.Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds per antagonistic review round; after that a maintainer, or the next antagonistic review, takes on any finding that remains, and a maintainer reviews every round before merge.
What changed and why
Python 3.10 is end of life. This package already requires
>=3.11, and ruff targetspy311, butpyproject.tomlstill ignored ruff'sUP006,UP007andUP035rules "for Python 3.10 compatibility". This PR removes those ignores and modernises the annotations they had been hiding. It changes annotations and imports only. Runtime behaviour does not change.The commits split the automatic fixes from the hand-written ones:
Refactor: Apply ruff PEP 585 and 604 autofixesis fully automatic. It is the output ofruff check --fix(UP006/UP007/UP035, then F401/I001, which drop the now-unusedtypingnames and re-sort imports) andruff format, scoped to the affected files:import_files.py,src/deprecations.py,src/{io,nss,ssl}.pyi,test/exceptions.pyandtypings/nss/error.pyi.typings/nss/{io,nss,ssl}.pyianddeprecations.pyare symlinks intosrc/, so they get the same fixes.Build(ruff): Enable UP006, UP007 and UP035 rulesis the hand-written change. It removes the three global ignores and adds thetest/setup_certs.pyper-file ignore described in the banner above.The 11
UP035findings that ruff could not fix on its own were alltypingimports left unused after the annotation rewrites. F401 removed them, so no hand edits to source were needed.Validation
ruff check src test scripts typings import_files.py(ruff 0.17.4, the hook's version, with the rules enabled): passes. (ruff check .still reports one F507 indoc/examples/cert_dump.py. That finding was already onmain, and the file is outside the hook's scope.)ruff format --checkon the same paths: passes.prek run --files <changed files>: every hook passes, including ruff, ruff-format, mypy, basedpyright (whole scope), reuse and gitlint.mypy src/*.pyi --ignore-missing-imports(as inadvanced-tests.yaml): no issues.uv sync --all-extras, thenuv pip install --no-build-isolation -e .against NSS 3.120 / NSPR 4.38.2): succeeds.uv run pytest: 428 passed, 21 skipped. This includestest/test_type_hints.py, whose|union syntax check of the stubs still passes.aislop scan --changes --json: emptydiagnostics, and no engine skipped.For reviewers
Union[str, int, Tuple[str, int], None]inNetworkAddress.__init__(src/io.pyi) is nowstr | int | tuple[str, int] | None. The two forms are equivalent.CallableandSequencenow come fromcollections.abcrather thantyping.test/setup_certs.pyis temporary. The banner above explains why it is needed and what removes it.