Skip to content

Refactor: Enable ruff's Python 3.11 upgrade rules - #293

Merged
ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-291
Nov 15, 2026
Merged

ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-291

Conversation

@lf-releng-code-monkey-bot

Copy link
Copy Markdown
Contributor

Closes #291

Authored by an AI agent; human review required
Command Exit
uvx ruff@0.17.4 check src test scripts typings import_files.py 0
uvx ruff@0.17.4 format --check src test scripts typings import_files.py 0
prek run --files <changed files> 0
uv run --no-sync mypy src/*.pyi --ignore-missing-imports 0
uv sync --all-extras 0
uv pip install --no-build-isolation -e . 0
uv run --no-sync pytest -q -p no:cacheprovider 0
aislop scan --changes --json 0
git log --raw --format=%h 1ec99106a58981dabe2f549c00235d73f7df5568..HEAD 0

The github-code-monkey-bot workflow 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.


INFO
test/setup_certs.py is an executable file (mode 100755), which this automated workflow cannot edit. It keeps a per-file ignore for UP006 and UP035 in pyproject.toml. Follow-up for a human: in that file, change from typing import List, Tuple and run_cmd(cmd_args: List[str], ...) -> Tuple[str, str] to builtin list/tuple, then remove "UP006", "UP035" (and the comment above) from the "test/setup_certs.py" entry in [tool.ruff.lint.per-file-ignores].

What changed and why

Python 3.10 is end of life. This package already requires >=3.11, and ruff targets py311, but pyproject.toml still ignored ruff's UP006, UP007 and UP035 rules "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:

  1. Refactor: Apply ruff PEP 585 and 604 autofixes is fully automatic. It is the output of ruff check --fix (UP006/UP007/UP035, then F401/I001, which drop the now-unused typing names and re-sort imports) and ruff format, scoped to the affected files: import_files.py, src/deprecations.py, src/{io,nss,ssl}.pyi, test/exceptions.py and typings/nss/error.pyi. typings/nss/{io,nss,ssl}.pyi and deprecations.py are symlinks into src/, so they get the same fixes.
  2. Build(ruff): Enable UP006, UP007 and UP035 rules is the hand-written change. It removes the three global ignores and adds the test/setup_certs.py per-file ignore described in the banner above.

The 11 UP035 findings that ruff could not fix on its own were all typing imports 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 in doc/examples/cert_dump.py. That finding was already on main, and the file is outside the hook's scope.)
  • ruff format --check on 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 in advanced-tests.yaml): no issues.
  • C extension build (uv sync --all-extras, then uv pip install --no-build-isolation -e . against NSS 3.120 / NSPR 4.38.2): succeeds.
  • uv run pytest: 428 passed, 21 skipped. This includes test/test_type_hints.py, whose | union syntax check of the stubs still passes.
  • aislop scan --changes --json: empty diagnostics, and no engine skipped.

For reviewers

  • Union[str, int, Tuple[str, int], None] in NetworkAddress.__init__ (src/io.pyi) is now str | int | tuple[str, int] | None. The two forms are equivalent.
  • Callable and Sequence now come from collections.abc rather than typing.
  • The per-file ignore for test/setup_certs.py is temporary. The banner above explains why it is needed and what removes it.

lf-releng-code-monkey-bot Bot and others added 2 commits November 15, 2026 23:03
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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 typing collections and unions with built-in generics and | syntax.
  • Moves Callable and Sequence imports to collections.abc.
  • Enables UP006, UP007, and UP035, retaining a documented temporary exception for test/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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 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.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit ef0f620 into lfreleng-actions:main Nov 15, 2026
65 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-291 branch November 15, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Enable ruff's Python 3.11 upgrade rules

2 participants