r/Python • • Feb 12 '23

Resource Python Interfaces: Choose Protocols Over ABC

https://levelup.gitconnected.com/python-interfaces-choose-protocols-over-abc-3982e112342e
64 Upvotes

20 comments sorted by

View all comments

138

u/[deleted] Feb 12 '23

Protocols and abstract classes are not interchangeable. You cannot simply choose one over the other. There is a substantial difference: abstract class ensures that an implementation meets certain requirements when a subclass is declared, while protocol checks if an instance meets certain requirements when it's being used. They are different in the same way as "They are of the same kind" and "There are things that both of them can do".

Please, don't confuse people with such articles.

1

u/CakeBearer1 Feb 13 '23

I wish I could upvote this more than once. This is exactly my response to this article. Thank you for saying it more succinctly and clearly than I could.