Re:Show HN: Rust-Like Traits in Python
by CornCobs on Sunday November 21, 2021 @08:07PM
(#29301539)
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?
[ Parent
| on HN ]
Just so. Yet, if there is interest in adding enough information to classes to support compile-time enforcement of interface requirements, ABCs to the rescue!
Re:Show HN: Rust-Like Traits in Python
by actuallyalys on Sunday November 21, 2021 @11:44PM
(#29302841)
To clarify, mypy already has compile-time (well, static checker-time) enforcement of protocols (https://mypy.readthedocs.io/en/stable/protocols.html) and ABCs (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]".
Re:Show HN: Rust-Like Traits in Python
by BerislavLopac on Sunday November 21, 2021 @08:32PM
(#29301718)
The beauty of Python is that it supports both nominal subtyping (class hierarchies) and structural subtyping (protocols).