dropbox / dropbox/sqlalchemy-stubs
Missing imports and arguments when using sqlalchemy.orm.DeclarativeBase
- Dominant language
- Python
- Stars
- 583
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Description
When I create a database following this guide: https://docs.sqlalchemy.org/en/20/orm/declarative_styles.html
Mypy says imports are missing and missing argument. The code itself works but I get errors with mypy. I am using Python 3.9
My file:
```
from datetime import datetime
from typing import Optional
from sqlalchemy import ForeignKey, create_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship, scoped_session, sessionmaker
from ..settings import DATABASE
class Base(DeclarativeBase):
pass
class Parent(Base):
__tablename__ = "parent_table"
id: Mapped[int] = mapped_column(primary_key=True)
children: Mapped[list["Child"]] = relationship(back_populates="parent")
class Child(Base):
__tablename__ = "child_table"
id: Mapped[int] = mapped_column(primary_key=True)
parent_id: Mapped[int] = mapped_column(ForeignKey("parent_table.id"))
parent: Mapped["Parent"] = relationship(back_populates="children")
```
My errors:
```
db.py:5: error: Module "sqlalchemy.orm" has no attribute "DeclarativeBase"
db.py:5: error: Module "sqlalchemy.orm" has no attribute "Mapped"; maybe "Mapper"?
db.py:5: error: Module "sqlalchemy.orm" has no attribute "mapped_column"
db.py:17: error: Missing positional argument "argument" in call to "RelationshipProperty"
db.py:24: error: Missing positional argument "argument" in call to "RelationshipProperty"
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.