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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/db_type.py
Original file line number Diff line number Diff line change
@@ -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.

from sqlalchemy.orm import * # noqa: F401,F403
6 changes: 4 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import itertools
import uuid
from enum import Enum
from typing import Any, Iterable, Literal
from typing import Any, Iterable, Literal, cast

from flask import current_app, url_for
from flask_sqlalchemy.model import DefaultMeta
Expand Down Expand Up @@ -33,6 +33,7 @@
from app import (
DATETIME_FORMAT,
db,
db_type,
signer_api_key,
signer_bearer_token,
signer_inbound_sms,
Expand All @@ -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. 👍

template_types = db.Enum(*TEMPLATE_TYPES, name="template_type")

NORMAL = "normal"
Expand Down Expand Up @@ -88,7 +90,7 @@ def update_from_original(self, original):
current_app.logger.debug("{} has no column {} to copy from".format(original, c.name))


BaseModel: DefaultMeta = db.Model
BaseModel: DefaultMeta = db.Model # type: ignore


class User(BaseModel):
Expand Down