From 31082420275e1862168da57e8da87dd9f79efe13 Mon Sep 17 00:00:00 2001 From: Juan Toledo Date: Mon, 20 May 2024 21:29:01 +0200 Subject: [PATCH] LINTING: mypy of models.py. 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. --- src/cambios/models.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/cambios/models.py b/src/cambios/models.py index cc21ead..4fddf00 100644 --- a/src/cambios/models.py +++ b/src/cambios/models.py @@ -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" @@ -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"