我正在尝试向我的SQLAlchemy脚本添加类型提示:
connection_string: str = "sqlite:///:memory:"
engine = create_engine(connection_string)
session = Session(bind=engine)
reveal_type(engine)
reveal_type(session)
我已经针对mypy
运行了此脚本,但是两种类型都以Any
的形式返回。 engine
和session
变量应该是什么类型?
答案 0 :(得分:1)
想通了:
connection_string: str = "sqlite:///:memory:"
engine = create_engine(connection_string)
session = Session(bind=engine)
print(type(engine)) # sqlalchemy.engine.base.Engine
print(type(session)) # sqlalchemy.orm.session.Session