Skip to content

Adopt PEP 585 / PEP 604 type hints (list[...], X | None, collections.abc) #642

Description

@nanotaboada

Problem

The project targets Python 3.13 (requires-python = ">=3.13.3") but still
imports generic types from typing:

  • List[Player], List[PlayerResponseModel]
  • Optional[Player], Optional[str]
  • Union[UUID, str]
  • typing.AsyncIterator, typing.AsyncGenerator

typing.List and friends are documented deprecated aliases; the
typing.AsyncIterator / AsyncGenerator aliases have been soft-deprecated in
favour of collections.abc since 3.9. New code on a modern interpreter should
use the builtin / collections.abc forms.

Proposed Solution

Sweep the annotations. Files affected: main.py, routes/player_route.py,
services/player_service.py, databases/player_database.py,
schemas/player_schema.py, tests/conftest.py.

Before After
from typing import List / List[X] list[X]
Optional[X] X | None
Union[A, B] A | B
from typing import AsyncIterator from collections.abc import AsyncIterator
from typing import AsyncGenerator from collections.abc import AsyncGenerator

Annotated stays imported from typing — it has no builtin equivalent.

Suggested Approach

  1. One file at a time: replace the annotations, then prune now-unused typing
    imports.
  2. Keep Annotated (and any future TypeVar / Protocol) from typing.
  3. Run uv run flake8 and uv run pytest after each file.
  4. AsyncGenerator[AsyncSession, None] becomes AsyncGenerator[AsyncSession]
    under collections.abc (the send type defaults to None).

Acceptance Criteria

  • No typing.List, typing.Optional, typing.Union remain
  • AsyncIterator / AsyncGenerator imported from collections.abc
  • Unused typing imports removed
  • flake8 clean, all tests pass
  • CHANGELOG.md updated

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority:lowNice-to-have improvement. Can be deferred without blocking other work.pythonPull requests that update Python codepython:idiomsRefactors toward idiomatic Python (PEP conventions, stdlib idioms)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions