5 ms·
I don't really understand the purpose of abstract base classes and interfaces in Python. Doesn't duck typing mean you are only interested in the concrete implem
by CornCobs 5y ago
I don't really understand the purpose of abstract base classes and interfaces in Python. Doesn't duck typing mean you are only interested in the concrete implementation?
- smitty1e 5y agoJust so. Yet, if there is interest in adding enough information to classes to support compile-time enforcement of interface requirements, ABCs to the rescue!
- BerislavLopac 5y agoThe beauty of Python is that it supports both nominal subtyping (class hierarchies) and structural subtyping (protocols).
- actuallyalys 5y agoTo clarify, mypy already has compile-time (well, static checker-time) enforcement of protocols (https://mypy.readthedocs.io/en/stable/protocols.html https://mypy.readthedocs.io/en/stable/protocols.html) and ABCs (https://mypy.readthedocs.io/en/stable/class_basics.html#abstract-base-classes-and-multiple-inheritance https://mypy.readthedocs.io/en/stable/class_basics.html#abst...). Maybe that's what you meant? The first time I read your comment I interpreted as "if there is interest [on the part of core Python developers]".