4 ms·
I didn't know about Protocol! How does this differ from ABC?
by tipsytoad 3y ago
I didn't know about Protocol! How does this differ from ABC?
- hmry 3y agoYou need to explicitly inherit from an ABC to be considered an instance of it. With Protocols you just need to match the interface, duck-typing style. (You can also do this with ABCs by writing custom __subclasscheck__ and __instancecheck__ functions, but those can't be statically checked, they only work at runtime) AFAIK protocols actually use ABCs internally(?) Just in a more constrained form that static type checkers can understand.