Skip to content

chore: Modernize Python tooling (ruff, uv, mypy)#8040

Open
phacops wants to merge 1 commit into
masterfrom
chore/modernize-python-tooling
Open

chore: Modernize Python tooling (ruff, uv, mypy)#8040
phacops wants to merge 1 commit into
masterfrom
chore/modernize-python-tooling

Conversation

@phacops

@phacops phacops commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Modernizes the Python lint/type toolchain and clears the debt the upgrades surface. Functionally a no-op for production code, but it expands static-analysis coverage and upgrades mypy across a major version. Reviewable as: tooling/config diffs (small) + a large mechanical sweep (autofixes) + targeted type fixes.

Ruff: expanded rule set

Adds B, UP, C4, SIM, RET to the existing E/F/W/I, enforces E402 (was blanket-ignored, which hid misplaced imports), and sets isort known-first-party. The ~5,100 resulting fixes are mostly mechanical typing modernization (Optional[X]X | None, Listlist). PEP 695 native-generic rules (UP040/046/047) are deliberately left ignored — mass-migrating generics under custom metaclasses is a separate, riskier change.

mypy: 1.1.1 → 2.1.0

A three-year version jump (mypyc-compiled). It surfaced 110 pre-existing errors that 1.1.1 silently missed — all fixed (41 redundant casts plus arg-type/attr-defined/type-arg across ~25 files). Also resolves the duplicate-conftest collision so mypy . runs clean, and aligns the pre-commit mypy hook's excludes with the config (pre-commit passes filenames explicitly, which bypassed mypy's own exclude).

type: ignore: 159 → 62

The reduction comes from fixing the underlying types, not suppressing. Every remaining ignore is now error-code-specific (# type: ignore[arg-type]) — zero bare, zero unused.

Config & housekeeping

pytest config moves from setup.cfg (deleted) into pyproject.toml; Makefile gains lint/lint-check/typecheck targets; the obsolete no-op tests/utils/conftest.py (overriding a fixture that no longer exists) is removed.

The stricter analysis also caught a few latent bugs, now fixed: test assertions that never asserted (bare comparisons), a profile_events call missing its clusterless_mode argument, and DeletionSettings constructed with positional args landing in the wrong fields.

Agent transcript: https://claudescope.sentry.dev/share/1JX1N9F7KUr3uBfmc57-ubJQKrY3XFoIPufiNWeh91w

Bring the lint/type toolchain up to modern standards and clear the debt
the upgrades surface.

Ruff: expand the lint set from E/F/W/I to add B (bugbear), UP (pyupgrade),
C4 (comprehensions), SIM (simplify) and RET (return), enforce E402, and set
isort known-first-party. Apply the resulting ~5,100 fixes (typing
modernization, comprehension/return cleanups). PEP 695 native-generic rules
(UP040/046/047) are deliberately left ignored - mass-migrating generics under
custom metaclasses is a separate, risky change.

mypy: upgrade 1.1.1 -> 2.1.0 (mypyc-compiled). The jump surfaced 110
pre-existing errors that 1.1.1 missed; all are fixed (41 redundant casts plus
arg-type/attr-defined/type-arg across ~25 files). Resolve the duplicate-conftest
collision and align the pre-commit mypy hook's excludes with the config so
'mypy .' and pre-commit check the same files.

type: ignore: reduce from 159 to 62 by fixing the underlying types; every
remaining suppression is now error-code-specific (zero bare, zero unused).

Config: move pytest config from setup.cfg (deleted) into pyproject.toml, add
Makefile lint/lint-check/typecheck targets, and remove the obsolete no-op
tests/utils/conftest.py.

Several latent bugs were caught in the process: missing test assertions, a
profile-events call missing an argument, and DeletionSettings constructed with
positional args in the wrong fields.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Agent transcript: https://claudescope.sentry.dev/share/DD3ny1HpZNB23VAt3zOpAjqDbo3ncHFJvSHXcXKnr-Y
@phacops phacops requested review from a team as code owners June 16, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant