dropbox / sqlalchemy-stubs

Mypy plugin and stubs for SQLAlchemy
Apache License 2.0
572 stars 102 forks source link

error: No library stub file for module 'sqlalchemy.ext.asyncio' #222

Open hydrargyrum opened 3 years ago

hydrargyrum commented 3 years ago

It seems the asyncio ext has no stubs.

CaselIT commented 3 years ago

As of sqlalchemy 1.4 it has a mypy plug-in that uses different stubs. https://docs.sqlalchemy.org/en/14/orm/extensions/mypy.html

hydrargyrum commented 3 years ago

So this project is for sqlalchemy 1.3 and you would recommend using sqlalchemy's plugin for 1.4+?

CaselIT commented 3 years ago

I don't know how well 1.4 is supported by this project. The current effort by sqlalchemy developers is on the sqlalchemy plugin that supports 1.4+

AntonOfTheWoods commented 3 years ago

This is pretty annoying. sqlalchemy 1.4 doesn't seem to be supported at all, and yet there is no restriction on the package for <1.4. Particularly as someone new to sqlalchemy and experimenting, this pointlessly wasted a couple of hours looking for a bug in VSCode's detection where there was none...

sangm commented 3 years ago

Since we use pyright, mypy plugin doesn't help with the mypy plugin.

will it take significant work to include the types here?

CaselIT commented 3 years ago

You can use https://pypi.org/project/sqlalchemy2-stubs/ also with pyright

sangm commented 3 years ago

@CaselIT

How so? The way I understand it is it uses a mypy plugin to wrap the types with internal types Mapped InstrumentedAttribute etc.

Using it without that plugin is not really feasible (as I understand)

CaselIT commented 3 years ago

I meant that most stuff should still work, at least in vscode it does (the python extension uses pyright iitc)

Obviously the stuff handled by the plugin will not work

sangm commented 3 years ago

For me the simplest case of

class Foo(..):
    id = Column(...)
foo = Foo(...)
foo.id = 2

does not work

CaselIT commented 3 years ago

The same error happens when using this library, so no change there.

from sqlalchemy.ext.declarative import declarative_base
import sqlalchemy as sa
Base = declarative_base()

class Foo(Base):
    __tablename__='foo'
    id = sa.Column(sa.Integer, primary_key=True)

foo = Foo()
foo.id = 42

fails for me with (using sqlalchemy-stubs==0.4 and pyright==0.0.9)

file.py10:5 - error: Cannot assign member "id" for type "Foo"
    Expression of type "Literal[42]" cannot be assigned to member "id" of class "Foo"
      "Literal[42]" is incompatible with "Column[int]" (reportGeneralTypeIssues)