Open hydrargyrum opened 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
So this project is for sqlalchemy 1.3 and you would recommend using sqlalchemy's plugin for 1.4+?
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+
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...
Since we use pyright, mypy plugin doesn't help with the mypy plugin.
will it take significant work to include the types here?
You can use https://pypi.org/project/sqlalchemy2-stubs/ also with pyright
@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)
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
For me the simplest case of
class Foo(..):
id = Column(...)
foo = Foo(...)
foo.id = 2
does not work
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)
It seems the asyncio ext has no stubs.