Skip to content

❓ Should model classes subclass protocols? #50

@demberto

Description

@demberto

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

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions