Flask-SQLAlchemy-Lite support for flask-migrate
Flask-SQLAlchemy-Lite was just released which is intended to be a replacement for Flask-SQLAlchemy. https://flask-sqlalchemy-lite.readthedocs.io/en/stable/
With that there is then a type conflict with flask_migrate:
https://github.com/python/typeshed/blob/main/stubs/Flask-Migrate/flask_migrate/init.pyi#L52
It expects flask_sqlalchemy.extension.SQLAlchemy, but flask_sqlalchemy_lite._extension.SQLAlchemy is now a compatible alternative
I'm pretty new to python so I'm not sure what the best approach to allow the flask_migrate typings to allow both.
Would it work to:
# ...
from flask_sqlalchemy import SQLAlchemy
from flask_sqlalchemy_lite import SQLAlchemy as SQLAlchemyLite
# ...
class Migrate:
configure_callbacks: list[_ConfigureCallback]
db: SQLAlchemy | SQLAlchemyLite | None
# ...
Or is there a better approach?
As I understand, flask-sqlalchemy-lite is already typed. Importing both flask_sqlalchemy and flask_sqlalchemy_lite in the stubs would be problematic, since that means that users would need to install both with the stubs or using conditional imports in the stubs.
I think the best solution here is to define a protocol in the flask-migrate stubs that describes the common interface used by flask migrate and import and depend on neither in the migrate stubs.