3 ms·
You 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
by hmry 3y ago
You 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.