Repository navigation
refactor: add type hints to flask_sqlalchemy.model - #8389
Conversation
|
I wasn't sure if this should be |
This comment has been minimized.
This comment has been minimized.
| class Model(Generic[_Model]): | ||
| query_class: type[Query[_Model]] | None | ||
| query: Query[_Model] | None |
There was a problem hiding this comment.
@srittau, does making Model generic look correct to you?
There was a problem hiding this comment.
Class implementation can be seen here, if it helps:
https://github.com/pallets-eco/flask-sqlalchemy/blob/main/src/flask_sqlalchemy/model.py#L115
There was a problem hiding this comment.
I have no experience with flask-sqlalchemy, but considering that sqlalchemy.orm.query is generic: probably.
There was a problem hiding this comment.
Let's YOLO it then. If it causes a problem for somebody, we'll know soon enough.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
The metaclasses are typed to match the following
type.__init__overload:https://github.com/python/typeshed/blob/master/stdlib/builtins.pyi#L167
As query's are generic in SQLAlchemy, this begins to make
Modelgeneric for use in theflask_sqlalchemy.__init__file once this is completed.This also updates
__table_cls__fromNameMetaMixin. This returns a table from:and then has a
Nonereturn if this branch hits:https://github.com/pallets-eco/flask-sqlalchemy/blob/main/src/flask_sqlalchemy/model.py#L90-L92
and the code runs to completion.