[Python] 'Variable not allowed in type expression' warning when creating SQLAchemy session...

Discussão em 'Python' iniciado por Stack, Agosto 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have a basic SQLAlchemy setup for a FastAPI project. I made a dependency for a database session like most tutorials suggest doing:

    from sqlalchemy.orm import sessionmaker

    SessionLocal = sessionmaker(engine, **sqlalchemy_session_options)

    def get_session() -> SessionLocal:
    with SessionLocal() as database:
    yield database


    But Pylance gives me "Variable not allowed in type expression" warning:

    [​IMG]

    I'm not super familiar with Pylance or type annotations. What should I do to fix this warning? Or should I just suppress it?

    Continue reading...

Compartilhe esta Página