I have a working Flask application which uses SQLAlchemy / flask_sqlalchemy. To give you an impression, I've created a super stripped down version (apps.py and models.py). The application works. The issue is that mypy complains about the usage of db.Model within models.py:
error: Name 'db.Model' is not defined
The reason is likely that this is created when db.init_app(app) is called. How can I fix this? Is there a better option than ignoring it?
# type: ignore
app.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def create_app():
app = Flask(__name__, template_folder="templates")
db.init_app(app)
return app
models.py
from app import db
class User(db.Model):
__tablename__ = "users"
id = db.Column(db.String, primary_key=True, nullable=False)
username = db.Column(db.String, unique=True)