-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor: add type hints to flask_sqlalchemy.model #8389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srittau, does making Model
generic look correct to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no experience with flask-sqlalchemy, but considering that sqlalchemy.orm.query
is generic: probably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Model
generic 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
None
return 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.