notification-api
notification-api copied to clipboard
Add better types to models.py
Summary | Résumé
Add better types to models.py.
How this works:
- the
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#L70 -
RoutingSQLAlchemy
hasflask_sqlalchemy.SQLAlchemy
as a base class -
flask_sqlalchemy.SQLAlchemy
has the following in its docstring:
This class also provides access to all the SQLAlchemy functions and classes from the
sqlalchemy
andsqlalchemy.orm
modules
- most of the things that are missing types in models.py can be found in these two paths, for instance
db.Column
is of typesqlalchemy.Column
,db.Boolean
is of typesqlalchemy.Boolean
,db.relationship
is of typesqlalchemy.orm.relationship
- so I just imported all the classes from these two paths into a new file, app/db_type.py, and assigned the
db
object to be that type - that populates most of the types in models.py:
Before:
After:
Test instructions | Instructions pour tester la modification
Tests should pass in CI, check out and try the new type hints locally!