Appearance
ADR-141: Modernize Python 3.10 Type Hint Syntax and Lock Ruff Rule Enforcements
- Status: Accepted
- Date: 2026-07-31
- Authors: @fderuiter
- Deciders: @fderuiter
1. Context & Problem Statement
Legacy Python typing constructs (typing.List, typing.Dict, typing.Optional, typing.Union) introduce verbose boilerplate and diverge from modern Python 3.10+ typing standards (PEP 585 built-in generic collections and PEP 604 union syntax A | B). Modernizing type hints across packages/security/ and pyproject.toml ensures static analysis precision and strict Ruff rule enforcement.
2. Decision Drivers & Constraints
- Enforce PEP 585 (
list[...],dict[...]) and PEP 604 (T | None) acrosspackages/security/and service modules. - Lock UP (pyupgrade) rules in
pyproject.tomlto prevent typing syntax regressions. - System requirement compliance: PRD-SYS-001.
3. Options Considered
Option 1: Modern Python 3.10+ PEP 585/604 Syntax Lock (Selected): Refactor legacy imports to native syntax and enable Ruff UP linter rules globally.
- Overview: Modern Python 3.10+ PEP 585/604 Syntax Lock (Selected): Refactor legacy imports to native syntax and enable Ruff UP linter rules globally.
- Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
Option 2: Maintain legacy typing.Optional and typing.List syntax.
- Overview: Maintain legacy
typing.Optionalandtyping.Listsyntax. - Pros:
- ✅ Satisfies architectural requirements
- Cons:
- ❌ Requires implementation and maintenance overhead
4. Decision Outcome
- Chosen Option: Option 1
- Justification: Chosen option 1 because built-in generic collections improve readability, reduce import overhead, and integrate cleanly with Pydantic v2 strict typing rules.
5. Consequences & Trade-offs
- Positive: Reduced typing import overhead and consistent code style across all
packages/security/modules. - Positive: Enforced via
uv run ruff check .in CI pipelines. - Negative: Requires modern Python 3.10+ runtime support.
6. Implementation & Verification
- Refactored
packages/security/,apps/gateway/, andapps/execution/. - Updated
pyproject.tomland verified usinguv run ruff check .anduv run pytest.