dropbox / dropbox/sqlalchemy-stubs
Enum interpreted as str
- Dominant language
- Python
- Stars
- 583
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Description
I have an SQLAlchemy model that makes use of the `Enum` column type. When accessing the field of an instance of this model, mypy believes that the type of the field is `str` even though it is actually an enum (e.g. `MyEnum`). This is annoying since, when I do want to access its value, mypy fails with `error: "str" has no attribute "value"`.
Although it cannot be run as such, the following snippet demonstrates the behavior when run through mypy. I would expect mypy to expect `m.state` should be of type `MyEnum` (really, in this snippet, it will be `None`, but in real code, it will be a `MyEnum`).
```python
import enum
from sqlalchemy import Column, Enum
from sqlalchemy.ext.declarative import declarative_base
class MyEnum(enum.Enum):
A = 'A'
B = 'B'
Base = declarative_base()
class MyModel(Base):
state = Column(Enum(MyEnum), nullable=False)
m = MyModel()
m.state.value
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.