You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromsqlalchemy.ext.declarativeimportdeclarative_basefromsqlalchemy.schemaimportColumnfromsqlalchemy.typesimportIntegerBase=declarative_base()
classBaseMixin(Base):
__abstract__=Truefield1=Column(Integer)
@classmethoddeffrom_something(cls, something_complicated: int) ->'BaseMixin':
# Real code tries to figure out which model to usereturnMyModel(field1=something_complicated, field2=something_complicated)
classMyModel(BaseMixin):
__tablename__='first-model'field2=Column(Integer)
With sqlalchemy-stubs from master, I get the following:
$ pipenv run mypy model.py
model.py:17: error: Unexpected column "field2" for model "MyModel"
But field2 exists on the model. 😕
This seems to be due to the order of the code because if I add the following line at the end of the file, then Mypy doesn't report any error:
m=MyModel(field1=1, field2=2)
The text was updated successfully, but these errors were encountered:
I think your diagnosis is correct, but this may be not easy to fix with the current state of mypy internals (we can't trigger a deferral from this point, because module top-levels can't be deferred).
Anyway, this is a known limitation in mypy, and it will likely be removed at some point soon.
Here is a very simplified reproducer:
With sqlalchemy-stubs from master, I get the following:
But
field2
exists on the model. 😕This seems to be due to the order of the code because if I add the following line at the end of the file, then Mypy doesn't report any error:
The text was updated successfully, but these errors were encountered: