Many model classes (classes which derive from ModelBase), support dunder methods like __getitem__, __iter__, __index__ etc. to make the API more Pythonic / idiomatic and remove the need for certain properties and clumsily named functions which achieve the same thing.
To make this more apparent, I subclass my model classes with protocols from typing or typing_extensions whenever possible.
I have been wondering whether this really is necessary? It has no other benefits than to show support for a certain protocol at runtime and isinstance checks with a ModelBase class and a protocol work just fine without subclassing the protocol. 🤔
React with 👍 if you think I should keep the way it is or 👎 if you don't
Many model classes (classes which derive from
ModelBase), support dunder methods like__getitem__,__iter__,__index__etc. to make the API more Pythonic / idiomatic and remove the need for certain properties and clumsily named functions which achieve the same thing.To make this more apparent, I subclass my model classes with protocols from
typingortyping_extensionswhenever possible.I have been wondering whether this really is necessary? It has no other benefits than to show support for a certain protocol at runtime and
isinstancechecks with aModelBaseclass and a protocol work just fine without subclassing the protocol. 🤔React with 👍 if you think I should keep the way it is or 👎 if you don't