Typing: of_type method not properly generic. #11371
Labels
PRs (with tests!) welcome
a fix or feature which is appropriate to be implemented by volunteers
typing
pep -484 typing issues. independent of "mypy"
Ensure stubs packages are not installed
sqlalchemy-stubs
andsqlalchemy2-stubs
are not compatible with v2)Verify if the api is typed
Describe the typing issue
of_type() method for QueryableAttribute is not properly made generic. This causes the type to not be set correctly and the result is not completely determined. This is only a minor nuisance as the correct type is not needed for any other checking.
To Reproduce
Error
MYPY
of_type_test.py:55: error: Need type annotation for "engineer_load" [var-annotated]
of_type_test.py:56: note: Revealed type is "sqlalchemy.orm.attributes.QueryableAttribute[]"
Pyright
.\of_type_test.py:55:1 - error: Type of "engineer_load" is partially unknown
Type of "engineer_load" is "QueryableAttribute[Unknown]" (reportUnknownVariableType)
.\of_type_test.py:56:13 - information: Type of "Team.employees.of_type(Engineer)" is "QueryableAttribute[Unknown]"
Versions
Additional context
Changing signature of the of_type method seems to fix it.
from:
def of_type(self, entity: _EntityType[Any]) -> QueryableAttribute[_T]:
to
def of_type(self, entity: _EntityType[_T]) -> QueryableAttribute[_T]:
Mypy:
of_type_test.py:56: note: Revealed type is "sqlalchemy.orm.attributes.QueryableAttribute[of_type_test.Engineer]"
Pyright:
\of_type_test.py:56:13 - information: Type of "Team.employees.of_type(Engineer)" is "QueryableAttribute[Engineer]"
The text was updated successfully, but these errors were encountered: