Skip to content

Commit

Permalink
LINTING: mypy of models.py. This is a hack due to flask_sqlalchemy se…
Browse files Browse the repository at this point in the history
…eeming incompatible with mypy. It is explained in pallets-eco/flask-sqlalchemy#1327.  I've tried all approaches and this seems to me the simplest hack to get mypy happy. We don't get autocomplete for model methods like query, but at least we do get type checking of columns.
  • Loading branch information
jtoledo1974 committed May 20, 2024
1 parent 812970b commit 3108242
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/cambios/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@

from .database import db

# This is a hack due to flask_sqlalchemy seeeming incompatible with mypy
# It is explained in https://github.com/pallets-eco/flask-sqlalchemy/issues/1327
# I've tried all approaches and this seems to me the simplest hack
# to get mypy happy.
# We don't get autocomplete for model methods like query, but at least
# we do get type checking of columns.

class User(db.Model):

class User(db.Model): # type: ignore[name-defined]
"""User model."""

__tablename__ = "users"
id = Column(Integer, primary_key=True)
firebase_uid = Column(String, unique=True)
email = Column(String(80), unique=True, nullable=False)
first_name = Column(String(100), nullable=False)
last_name = Column(String(100), nullable=False)
category = Column(String(50), nullable=False)
team = Column(String(1))
license_number = Column(String(50), nullable=False)
is_admin = Column(Boolean, default=False)
email: str = Column(String(80), unique=True, nullable=False) # type: ignore[assignment]
first_name: str = Column(String(100), nullable=False) # type: ignore[assignment]
last_name: str = Column(String(100), nullable=False) # type: ignore[assignment]
category: str = Column(String(50), nullable=False) # type: ignore[assignment]
team: str = Column(String(1)) # type: ignore[assignment]
license_number: str = Column(String(50), nullable=False) # type: ignore[assignment]
is_admin: bool = Column(Boolean, default=False) # type: ignore[assignment]


class Shift(db.Model):
class Shift(db.Model): # type: ignore[name-defined]
"""Shift model."""

__tablename__ = "shifts"
Expand All @@ -35,7 +42,7 @@ class Shift(db.Model):
user = relationship("User", backref="shifts")


class ShiftTypes(db.Model):
class ShiftTypes(db.Model): # type: ignore[name-defined]
"""Shift types model."""

__tablename__ = "shift_types"
Expand Down

0 comments on commit 3108242

Please sign in to comment.