Skip to content
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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Add better types to models.py #1885

wants to merge 6 commits into from

Conversation

smcmurtry
Copy link
Contributor

@smcmurtry smcmurtry commented Jun 2, 2023

Summary | Résumé

Add better types to models.py.

How this works:

This class also provides access to all the SQLAlchemy functions and classes from the sqlalchemy and sqlalchemy.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 type sqlalchemy.Column, db.Boolean is of type sqlalchemy.Boolean, db.relationship is of type sqlalchemy.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:
Screenshot 2023-06-02 at 4 33 30 PM
Screenshot 2023-06-02 at 4 36 10 PM

After:
Screenshot 2023-06-02 at 4 33 54 PM
Screenshot 2023-06-02 at 4 35 13 PM

Test instructions | Instructions pour tester la modification

Tests should pass in CI, check out and try the new type hints locally!

@@ -0,0 +1,2 @@
from sqlalchemy import * # noqa: F401,F403
Copy link
Member

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
Copy link
Member

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. 👍

@smcmurtry smcmurtry marked this pull request as draft August 9, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants