[Python] Why does mypy does not work with sqlalchemy?

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following code (snippet):

    from sqlalchemy.orm import declarative_base

    Base = declarative_base()


    with pip I installed

    $ pip install -U sqlalchemy[mypy] sqlalchemy-stubs mypy
    $ pip list | egrep -i '(sqlal|mypy)'
    mypy 0.982
    mypy-extensions 0.4.3
    SQLAlchemy 1.4.42
    sqlalchemy-stubs 0.4
    SQLAlchemy-Utils 0.38.3
    sqlalchemy2-stubs 0.0.2a29


    Still, when running mypy file.py, I'm getting:

    $ python3 -mmypy test.py
    test.py:1: error: Module "sqlalchemy.orm" has no attribute "declarative_base"
    Found 1 error in 1 file (checked 1 source file)


    I'm using Python 3.10.5 from within a virtualenv.

    What can I do to debug more?

    Continue reading...

Compartilhe esta Página