sqlalchemy2-stubs: 'DeclarativeMeta' is not defined
Describe your question
When creating a Base class with @as_declarative the following errors shows up using mypy error: Name 'DeclarativeMeta' is not defined
. Am I doing something wrong or is there a better way?
Example - please use the Minimal, Complete, and Verifiable guidelines if possible Using the example as provided in the documentation, it works without a problem:
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
name = Column(String)
addresses: Mapped[List["Address"]] = relationship("Address", back_populates="user")
class Address(Base):
__tablename__ = 'address'
id = Column(Integer, primary_key=True)
user_id: int = Column(ForeignKey("user.id"))
user: Mapped[User] = relationship(User, back_populates="addresses")
main mypy --config mypy.ini --strict simple-test.py
Success: no issues found in 1 source file
When trying to use it as following it shows the error:
@as_declarative()
class Base(object):
id = Column(Integer, primary_key=True)
class User(Base):
__tablename__ = "user"
name = Column(String)
addresses: Mapped[List["Address"]] = relationship("Address", back_populates="user")
class Address(Base):
__tablename__ = "address"
user_id: int = Column(ForeignKey("user.id"))
user: Mapped[User] = relationship(User, back_populates="addresses")
main mypy --config mypy.ini --strict simple-test.py
simple-test.py: error: Name 'DeclarativeMeta' is not defined
mypy config
[mypy]
plugins = sqlalchemy.ext.mypy.plugin
Versions
- OS: MacOS 11.0
- Python: Python 3.9.2
- Mypy: mypy 0.812
- SQLAlchemy: 1.4.3
- sqlalchemy2-stub: 0.0.1a4
- Database: n/a
- DBAPI: n/a
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (16 by maintainers)
I think it’s currently required for how the plugin works. In any case this issue seems different from this one, so if you could open a new issue it would be great