Понадобилось мне тут накидать небольшой CRUD, я по старой памяти рачехлил Flask,а заодно и решил донастроить neovim как Python IDE с помощью новомодных lsp/pyright/cmp. И тут же наступил ногами в жир:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy(app)
class User(db.Model): ■ Expected type expression but received "type"
id = db.Column(db.Integer, primary_key=True)
Гуглинг привел к issue к pyright, а оттуда и на подобную к mypy.
И вот что там пишет один бедолага:
I’m removing Flask-SQLAlchemy from my code entirely. I’ve moved most references of db.* to sa.* and sa.orm.* so I could get type checking. Next step: replacing db.Model with a custom base model, then db.session.
This has been a nightmare year with perfectly functional code falling apart every few months as various framework libraries refactor themselves to fit into the constraints of static typing.
Static type checking has been an excellent development for Python – it’s significantly reduced the need for test coverage of data types, or defensive code to evaluate function parameters – but it’s also shrunk the dynamic nature of Python to the subset recognised by type checkers. My project now has an average of five # type: ignore lines per Python file, and I’ve spent way too much time this year on (a) researching ways to make an idiom type-compatible, and (b) giving up and adding an ignore.