'DeclarativeMeta' is not defined
See original GitHub issueDescribe 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:22 (16 by maintainers)
Top Results From Across the Web
SQLAlchemy declarative one-to-many not defined error
I'm trying to figure how to define a one-to-many relationship using SQLAlchemy's declarative ORM, and trying to get the example to work, ......
Read more >sqlalchemy.ext.declarative DeclarativeMeta Example Code
Example code for understanding how to use the DeclarativeMeta class from the sqlalchemy.ext.declarative module of the SQLAlchemy project.
Read more >Declarative API — SQLAlchemy 1.3 Documentation
The AbstractConcreteBase class does not intend to set up the mapping for the base class until all the subclasses have been defined, as...
Read more >Cannot define declarative base class as attribute of object #54
I'd like to switch from the dropbox/sqlalchemy stubs to the official stubs, however when the declarative base is defined as attribute of an...
Read more >Python sqlalchemy.ext.declarative.DeclarativeMeta() Examples
This page shows Python examples of sqlalchemy.ext.declarative.DeclarativeMeta.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
@CaselIT Thanks, i just opened new issue.