-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add better types to models.py #1885
base: main
Are you sure you want to change the base?
Conversation
…ion-api into feat/types-in-models-2
@@ -0,0 +1,2 @@ | |||
from sqlalchemy import * # noqa: F401,F403 |
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 please document the purpose of this file with a docstring, explaining why this is necessary.
@@ -50,6 +51,7 @@ | |||
|
|||
TEMPLATE_TYPES = [SMS_TYPE, EMAIL_TYPE, LETTER_TYPE] | |||
|
|||
db = cast(db_type, db) # type: ignore |
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.
And a comment to explain why we need to cast it to the module's type. 👍
Summary | Résumé
Add better types to models.py.
How this works:
db
object in models.py is an instance of theRoutingSQLAlchemy
class defined here: https://github.com/cds-snc/notification-api/blob/main/app/dbsetup.py#L70RoutingSQLAlchemy
hasflask_sqlalchemy.SQLAlchemy
as a base classflask_sqlalchemy.SQLAlchemy
has the following in its docstring:db.Column
is of typesqlalchemy.Column
,db.Boolean
is of typesqlalchemy.Boolean
,db.relationship
is of typesqlalchemy.orm.relationship
db
object to be that typeBefore:
After:
Test instructions | Instructions pour tester la modification
Tests should pass in CI, check out and try the new type hints locally!