Open
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
).
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