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
It's common to use meta classes as a way to define models, eg:
classModel(Base):
my_column=Column(SomeType, ...)
This sort of pattern occurs in many places including ORMs and serialisation libraries, basically anything where a schema of some kind is needed.
What they all share is that the RHS of assignments in the class definition describe the type of those attributes on instances of the class, rather than the value of those attributes.
I think it would be worthwhile special-casing this usage: allow annotating a meta class with a type signature which tells mypy how to handle members. For the example above:
classBaseMeta(type):
# field-generator: (Column[T]) -> T
...
This would give mypy the information it needs to determine the correct type of my_column.
The text was updated successfully, but these errors were encountered:
That seems reasonable, but there doesn't seem to be any documentation or examples about how to write plugins for mypy. I think I've read most of the documentation and until you mentioned it was unaware that mypy even supported plugins?
It's common to use meta classes as a way to define models, eg:
This sort of pattern occurs in many places including ORMs and serialisation libraries, basically anything where a schema of some kind is needed.
What they all share is that the RHS of assignments in the class definition describe the type of those attributes on instances of the class, rather than the value of those attributes.
I think it would be worthwhile special-casing this usage: allow annotating a meta class with a type signature which tells mypy how to handle members. For the example above:
This would give mypy the information it needs to determine the correct type of
my_column
.The text was updated successfully, but these errors were encountered: