Just wanted to mention that there is an interesting bit about structural subtyping using mypy typing_extensions in the article.
Thank you for drawing attention to that section of your article. I have an instance of it whereby I have a variety of kinds of equipment that are rack mountable. In designing classes for this scenario you typically see some kind of abstract base class like physical-machine or rackable-computer or similar. I don’t like solving the problem that way, as those classes are not real in the same way a switch or a dom0 is. The equipment has compatible physical properties, more realistically expressed as an interface.
Seeing an example of accomplishing this in Python is a treat. I have not encountered Mypy before.
Mypy is a static type checker for Python. It’s still not as common as it should be, but it’s gaining traction.
The motivation for using a Protocol is static type checking. The protocol does not act as an interface or abstract base class as you might know it from other languages.
We also started with abstract base classes but we quickly realized they are not a good fit for Django models (as described in the article, they cause some problems with migrations).
If you like the concept take a look at go.