Skip to content

Tighten mypy and ruff configuration#457

Open
sandhose wants to merge 7 commits intoquenting/modern-tooling/toolingfrom
quenting/modern-tooling/lint
Open

Tighten mypy and ruff configuration#457
sandhose wants to merge 7 commits intoquenting/modern-tooling/toolingfrom
quenting/modern-tooling/lint

Conversation

@sandhose
Copy link
Copy Markdown
Member

@sandhose sandhose commented Apr 2, 2026

Summary

  • Replace deprecated logger.warn() with logger.warning()
  • Add missing type annotations and tighten mypy config (disallow_untyped_defs now passes on all modules)
  • Narrow type: ignore comments to specific error codes and enable warn_unused_ignores
  • Enable warn_return_any in mypy and fix all violations
  • Enable ruff rules: UP (pyupgrade), B (bugbear), C4, SIM, RUF, PIE, RSE, G, PERF, TC
  • Drop explicit target-version from ruff config (inferred from requires-python)
  • Modernize type annotations to Python 3.10+ syntax (dict not Dict, X | Y not Union)
  • Add from err to raise-in-except blocks, merge nested with statements, annotate ClassVar
  • Remove dead ProxyConnectError exception class (unused after Twisted removal)
  • Remove # -*- coding: utf-8 -*- declarations (unnecessary since Python 3)

Notes

  • _choppable_get in apnstruncate.py now raises ValueError instead of implicitly returning None for unknown choppable types. The branches are exhaustive so this is unreachable in practice.
  • warn_return_any = False for sygnal.apnstruncate module — needed due to dict[str, Any] access patterns.
  • PERF203 (try-except in loop) is suppressed — the loops have intentional error handling.

Test plan

  • uv run mypy sygnal/ tests/ passes with zero errors
  • uv run ruff check sygnal/ tests/ passes
  • uv run pytest tests/ — 55 tests pass
  • CI green

Part 6 of 7 in the repository modernisation series. Builds on #456.

@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 285d656 to d8149ff Compare April 2, 2026 12:36
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch 2 times, most recently from 0fbb49c to 5e8b2d1 Compare April 2, 2026 16:53
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch 2 times, most recently from 3268987 to ab14e48 Compare April 2, 2026 17:29
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 5e8b2d1 to a56e1c5 Compare April 2, 2026 17:29
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from ab14e48 to cf4025a Compare April 2, 2026 17:39
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch 2 times, most recently from 764bfcb to 7595c86 Compare April 2, 2026 17:58
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch 2 times, most recently from 93772ed to 92d116c Compare April 2, 2026 22:18
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 7595c86 to 0fac7bb Compare April 2, 2026 22:18
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 92d116c to 43fdd6d Compare April 2, 2026 22:38
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 0fac7bb to 9816f5f Compare April 2, 2026 22:38
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 43fdd6d to cf97bee Compare April 2, 2026 22:48
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch 2 times, most recently from c8f4a4d to 32a254c Compare April 2, 2026 22:52
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch 2 times, most recently from 6af2185 to 85f3e42 Compare April 2, 2026 23:02
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 32a254c to 6850192 Compare April 2, 2026 23:02
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 85f3e42 to 5cbdc57 Compare April 2, 2026 23:05
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 6850192 to 2e6715e Compare April 2, 2026 23:05
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 5cbdc57 to 6882db4 Compare April 3, 2026 10:21
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 2e6715e to a1bf2b9 Compare April 3, 2026 10:21
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 6882db4 to 5b98dc0 Compare April 3, 2026 10:22
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from a1bf2b9 to 3ce7d40 Compare April 3, 2026 10:22
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 5b98dc0 to 22a1320 Compare April 3, 2026 11:34
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 3ce7d40 to ab52477 Compare April 3, 2026 11:34
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 22a1320 to 1b61f12 Compare April 3, 2026 11:38
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from ab52477 to 31bc4e6 Compare April 3, 2026 11:38
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 35792ef to 4d381f3 Compare April 3, 2026 13:24
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch 2 times, most recently from 2b50fc9 to 56b7c1c Compare April 3, 2026 13:28
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 4d381f3 to 0ccfa57 Compare April 3, 2026 13:28
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 56b7c1c to 143fb98 Compare April 3, 2026 13:33
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch 2 times, most recently from 5214b04 to cd9fbb6 Compare April 3, 2026 13:40
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 143fb98 to 24feab2 Compare April 3, 2026 13:40
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch 2 times, most recently from f975771 to 7fc88c8 Compare April 3, 2026 14:00
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 6f8546b to 17a648c Compare April 3, 2026 14:00
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 7fc88c8 to b7305b6 Compare April 3, 2026 14:10
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch 2 times, most recently from 1f24aa4 to c6bdaa6 Compare April 3, 2026 14:15
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch 2 times, most recently from b513718 to 462b67b Compare April 3, 2026 14:30
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from c6bdaa6 to 6bf3f1f Compare April 3, 2026 14:30
@sandhose sandhose marked this pull request as ready for review April 3, 2026 14:47
@sandhose sandhose requested a review from a team as a code owner April 3, 2026 14:47
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from 462b67b to bc34152 Compare April 3, 2026 14:58
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 6bf3f1f to 6c3b661 Compare April 3, 2026 14:58
sandhose added 7 commits April 3, 2026 17:02
logging.warn() was deprecated in Python 3.3. All call sites already
use module-scoped loggers via logging.getLogger(__name__).
Remove stale mypy overrides that are no longer needed:
- prometheus_client now ships py.typed
- All four disallow_untyped_defs=False overrides pass strict

Add missing type annotations to testutils and notifications.py
to satisfy the now-strict config.
Replace `type: ignore[assignment]` with the narrower
`type: ignore[method-assign]` on all test monkeypatching lines,
as suggested by mypy 1.20. Enable warn_unused_ignores in mypy.ini
to catch stale ignores going forward.
Add warn_return_any to catch implicit Any returns. Fix by:
- Extracting dict values into typed locals (notifications.py)
- Adding an else branch to exhaustive if/elif (apnstruncate.py)
- Typing the dynamic getattr result (sygnal.py)
- Typing yaml.safe_load result (sygnal.py)
- Typing self.client as TestClient (testutils.py)
Enable UP (pyupgrade), B (bugbear), C4 (comprehensions), SIM
(simplify), RUF (ruff-specific), PIE, and RSE rule sets.

Key changes:
- Modernize type annotations to Python 3.11+ syntax (dict, list,
  X | Y instead of Dict, List, Union)
- Remove utf-8 coding declarations
- Add `from err` to raise-in-except blocks (B904)
- Merge nested with statements (SIM117)
- Annotate mutable class defaults with ClassVar (RUF012)
- Replace contextlib.suppress for try/except/pass (SIM105)
- Simplify dict comprehension and string formatting
No longer used after the Twisted proxy infrastructure was removed.
@sandhose sandhose force-pushed the quenting/modern-tooling/tooling branch from 6c3b661 to abb4bab Compare April 3, 2026 15:02
@sandhose sandhose force-pushed the quenting/modern-tooling/lint branch from bc34152 to dce869b Compare April 3, 2026 15:02
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.

1 participant