-
Notifications
You must be signed in to change notification settings - Fork 25
Adopt PEP 585 / PEP 604 type hints (list[...], X | None, collections.abc) #642
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestpriority:lowNice-to-have improvement. Can be deferred without blocking other work.Nice-to-have improvement. Can be deferred without blocking other work.pythonPull requests that update Python codePull requests that update Python codepython:idiomsRefactors toward idiomatic Python (PEP conventions, stdlib idioms)Refactors toward idiomatic Python (PEP conventions, stdlib idioms)
Description
Activity
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestpriority:lowNice-to-have improvement. Can be deferred without blocking other work.Nice-to-have improvement. Can be deferred without blocking other work.pythonPull requests that update Python codePull requests that update Python codepython:idiomsRefactors toward idiomatic Python (PEP conventions, stdlib idioms)Refactors toward idiomatic Python (PEP conventions, stdlib idioms)
Problem
The project targets Python 3.13 (
requires-python = ">=3.13.3") but stillimports generic types from
typing:List[Player],List[PlayerResponseModel]Optional[Player],Optional[str]Union[UUID, str]typing.AsyncIterator,typing.AsyncGeneratortyping.Listand friends are documented deprecated aliases; thetyping.AsyncIterator/AsyncGeneratoraliases have been soft-deprecated infavour of
collections.abcsince 3.9. New code on a modern interpreter shoulduse the builtin /
collections.abcforms.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.from typing import List/List[X]list[X]Optional[X]X | NoneUnion[A, B]A | Bfrom typing import AsyncIteratorfrom collections.abc import AsyncIteratorfrom typing import AsyncGeneratorfrom collections.abc import AsyncGeneratorAnnotatedstays imported fromtyping— it has no builtin equivalent.Suggested Approach
typingimports.
Annotated(and any futureTypeVar/Protocol) fromtyping.uv run flake8anduv run pytestafter each file.AsyncGenerator[AsyncSession, None]becomesAsyncGenerator[AsyncSession]under
collections.abc(the send type defaults toNone).Acceptance Criteria
typing.List,typing.Optional,typing.UnionremainAsyncIterator/AsyncGeneratorimported fromcollections.abctypingimports removedflake8clean, all tests passCHANGELOG.mdupdatedReferences
X | Ytyping— Deprecated aliases