sqlalchemy-stubs icon indicating copy to clipboard operation
sqlalchemy-stubs copied to clipboard

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

Open hydrargyrum opened this issue 4 years ago • 10 comments

It seems the asyncio ext has no stubs.

hydrargyrum avatar Jun 28 '21 16:06 hydrargyrum

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

CaselIT avatar Jul 14 '21 08:07 CaselIT

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

hydrargyrum avatar Jul 14 '21 08:07 hydrargyrum

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+

CaselIT avatar Jul 14 '21 08:07 CaselIT

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...

AntonOfTheWoods avatar Jul 17 '21 00:07 AntonOfTheWoods

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

will it take significant work to include the types here?

sangm avatar Aug 29 '21 01:08 sangm

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

CaselIT avatar Aug 29 '21 06:08 CaselIT

@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)

sangm avatar Aug 29 '21 22:08 sangm

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

CaselIT avatar Aug 29 '21 22:08 CaselIT

For me the simplest case of

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

does not work

sangm avatar Aug 30 '21 00:08 sangm

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)

CaselIT avatar Aug 30 '21 12:08 CaselIT