Skip to content

Modernize tools, drop from __future__ import annotations, and fix lint CI#10

Merged
shenanigansd merged 4 commits into
mainfrom
claude/focused-feynman-dy4nbx
Jun 20, 2026
Merged

Modernize tools, drop from __future__ import annotations, and fix lint CI#10
shenanigansd merged 4 commits into
mainfrom
claude/focused-feynman-dy4nbx

Conversation

@shenanigansd

Copy link
Copy Markdown
Member

Summary

Gets the Python lint and test workflow green, removes from __future__ import annotations, and gives the three tools/ scripts a modernization pass — while keeping stdlib_introspect.py runnable on the 3.10–3.15 introspect matrix.

Fixing the lint CI

The lint job was failing for several reasons:

  • mypy pointed at directories that don't exist (src/ packages/ tests/) — repointed at the real code, tools/ + noxfile.py (in the workflow and the noxfile).
  • mypy loaded a pydantic.mypy plugin that isn't a dependency → removed.
  • coverage_diff.py imports sphobjinv, unresolved for the type checkers → declared it as a project dependency (so uv sync resolves it), told mypy it ships no py.typed, and silenced ty's false positive on its attrs-generated constructor.
  • select = ["ALL"] + unannotated code produced 243 ruff errors → fixed the code and curated a small, justified ignore / per-file-ignores list (formatter conflicts, the TC family which assumes stringized annotations, and per-file allowances for CLI print / boolean-trap / arg-count / broad-except / url-open).

Modernization

  • Removed from __future__ import annotations from all three tools.
  • Full type annotations everywhere; PEP 695 type aliases for the record / version-key shapes.
  • pathlib over os.path/glob/open; itertools.pairwise over zip(x, x[1:]); a dict comprehension for the union build; contextlib.suppress over try/except/pass.
  • Named the magic comparison values, added docstrings, dropped the now-dead sys.stdlib_module_names guard and an unused parameter.

Python-version scoping

stdlib_introspect.py runs across the stdlib-introspect matrix (Python 3.10–3.15), while merge_summary.py and coverage_diff.py run on the aggregate/coverage jobs' "3.x". So:

  • stdlib_introspect.py stays 3.10-compatible: TypeAlias (with a per-file UP040 ignore) and contextlib.suppress instead of a except (A, B) tuple that the py314 formatter would rewrite into the 3.14-only PEP 758 form.
  • merge_summary.py / coverage_diff.py use modern-only syntax and lint at the repo's 3.14 default.

requires-python = ">=3.14" is the dev/tooling floor; only this one script carries the older runtime floor.

Verification

  • ruff (format + check), mypy --strict, ty, and prek all pass on 3.14.
  • stdlib_introspect.py compiles and runs on Python 3.10 (17,129 records); merge_summary.py and coverage_diff.py run on 3.14.
  • End-to-end: introspect → merge (correct 3.13→3.14 deltas) → coverage diff (gap computed against live docs.python.org inventories).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Rh5G5LSDPMWLgX3cYLWUnk


Generated by Claude Code

claude added 3 commits June 20, 2026 23:10
The lint CI pointed mypy at directories that don't exist
(src/packages/tests) while the real code lives in tools/, the code
carried no annotations (so mypy --strict and ruff's ANN/D rules failed),
the mypy config loaded a pydantic plugin that isn't a dependency, and
coverage_diff's sphobjinv import was unresolved for the type checkers.

Tooling:
- Point mypy at tools/ + noxfile.py in the workflow and the noxfile
- Declare sphobjinv as a dependency so `uv sync` resolves it; tell mypy
  it ships no py.typed marker
- Drop the unused pydantic.mypy plugin
- Curate a ruff ignore list for select=ALL: formatter conflicts, the TC
  family (it assumes stringized annotations), and per-file allowances for
  CLI print / boolean-trap / arg-count / broad-except / url-open

Code:
- Remove `from __future__ import annotations` from all three tools
- Add full type annotations; PEP 695 `type` aliases for the record and
  version-key shapes
- pathlib over os.path/glob/open; itertools.pairwise over zip(x, x[1:]);
  a dict comprehension for the union build
- Name the magic comparison values and add docstrings
- Drop the now-dead sys.stdlib_module_names guard and an unused
  _markdown_summary parameter

ruff (format + check), mypy --strict, ty, and prek all pass; the three
tools still run end-to-end (introspect -> merge -> coverage diff).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rh5G5LSDPMWLgX3cYLWUnk
The stdlib-introspect matrix runs these scripts on Python 3.10-3.15, but
the previous commit (and #8) left them using newer syntax that 3.10-3.13
cannot parse:
- PEP 695 `type X = ...` aliases -> `TypeAlias`
- PEP 758 parenthesis-free `except A, B:` -> parenthesized

Add tools/ruff.toml pinning target-version = py310 (extending the root
config) so Ruff lints these files at the matrix floor rather than the
repo's dev requirement -- otherwise UP040 demands the `type` statement
back. That lower target re-enables PERF203 (a no-op once exceptions are
zero-cost), so ignore it for the tools' I/O retry/parse loops.

The rest of the modernization (annotations, pathlib, itertools.pairwise,
docstrings, dropped __future__ import) is already 3.10-compatible and
stays. Verified: ruff/mypy/ty/prek pass on the 3.14 dev env; all three
tools compile on 3.10, and stdlib_introspect + merge_summary run there.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rh5G5LSDPMWLgX3cYLWUnk
Only stdlib_introspect.py runs across the introspect matrix (3.10-3.15);
merge_summary.py and coverage_diff.py run on the aggregate/coverage jobs'
"3.x", so they don't need legacy support. The previous commit pinned all
of tools/ to py310 via tools/ruff.toml, which over-applied the floor.

Ruff's target-version is directory-scoped, not per-file, so instead of a
directory config this scopes the one genuine conflict precisely:
- stdlib_introspect.py keeps `TypeAlias` and ignores UP040 (which would
  demand the 3.12 `type` statement) for that file only. Its
  `except (ValueError, TypeError)` becomes `contextlib.suppress(...)` --
  3.10-safe, idiomatic (SIM105), and not something the py314 formatter
  rewrites into the parenthesis-free PEP 758 form.
- merge_summary.py and coverage_diff.py go back to PEP 695 `type` aliases
  and lint at the repo's py314 default.

Drop tools/ruff.toml and the PERF203 ignore (a no-op once try/except is
zero-cost, which is where these two now lint).

Verified: ruff/mypy/ty/prek pass; stdlib_introspect compiles and runs on
3.10, while the other two use modern-only syntax and run on 3.14.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rh5G5LSDPMWLgX3cYLWUnk
Copilot AI review requested due to automatic review settings June 20, 2026 23:38
Comment thread tools/merge_summary.py Fixed

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.

Pull request overview

This PR modernizes the tools/ scripts (types, pathlib, small refactors), removes from __future__ import annotations, and updates the lint workflow/nox session so CI type-checks the directories that actually exist. It also adds sphobjinv as a dependency to satisfy type-checking/runtime needs for coverage_diff.py.

Changes:

  • Fix lint CI failures by updating mypy targets (workflow + nox) and adjusting tool config/deps (notably sphobjinv).
  • Modernize tools/stdlib_introspect.py, tools/merge_summary.py, and tools/coverage_diff.py with fuller typing, pathlib, and other cleanup.
  • Update lockfile to reflect the new dependency set.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
uv.lock Adds sphobjinv and its transitive dependencies to the lock.
tools/stdlib_introspect.py Removes future import; adds typing/pathlib refactors while keeping 3.10 compatibility.
tools/merge_summary.py Modernizes aggregation/typing and uses pathlib/pairwise.
tools/coverage_diff.py Modernizes typing/pathlib; adjusts HTTP handling and inventory loading.
pyproject.toml Declares sphobjinv dependency; refines ruff ignores; removes mypy plugin and adds overrides.
noxfile.py Updates mypy invocation to check tools/ and noxfile.py.
.github/workflows/python-ci.yaml Updates mypy invocation to check tools/ and noxfile.py.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/coverage_diff.py Outdated
- CodeQL (implicit-string-concatenation-in-list): the line-wrapped prose
  strings in the report() blocks are now extracted to named locals
  (no_cells, deltas_intro, core_breakdown), matching the no_versions /
  intro style already used elsewhere. No behavior change; clears the alert
  and the missing-comma ambiguity.
- Copilot (coverage_diff.http_get): guard `attempts < 1` with a ValueError
  so a bad argument no longer falls through to the end-of-function
  AssertionError, which is now genuinely unreachable.

ruff/mypy/ty pass; merge_summary and coverage_diff still run end-to-end.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rh5G5LSDPMWLgX3cYLWUnk
@shenanigansd shenanigansd merged commit adf42b5 into main Jun 20, 2026
5 checks passed
@shenanigansd shenanigansd deleted the claude/focused-feynman-dy4nbx branch June 20, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants