-
Notifications
You must be signed in to change notification settings - Fork 25
Type collection returns as Sequence[Player], not List[Player] #646
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
services/player_service.py::retrieve_all_asyncis annotated-> List[Player],but
result.scalars().all()is typedSequence[Player]by SQLAlchemy 2.0 —not necessarily a
list. The annotation is inaccurate and over-promises:callers are told they can
.append()or do item assignment on a value that maynot support it.
Proposed Solution
Type collection-returning read operations with
collections.abc.Sequence:The only caller (
get_all_asyncinroutes/player_route.py) caches the valueand returns it through a
list[PlayerResponseModel]response_model, whichFastAPI builds from any iterable — so
Sequenceis sufficient. This is thecollections.abcprinciple: annotate with the least specific type that isactually true.
Suggested Approach
retrieve_all_asyncreturn annotation toSequence[Player].issue) so all the
collections.abcimports land at once.uv run flake8anduv run pytest.Acceptance Criteria
retrieve_all_asyncreturnsSequence[Player]flake8clean, all tests passCHANGELOG.mdupdatedReferences
collections.abc— Abstract Base Classes for ContainersScalarResult.all()