4 ms·
I had looked into protocols the other day but found no advantages over ABCs. In fact, failing to implement an ABC's interface is a 'compile-time' error, which i
by diarrhea 4y ago
I had looked into protocols the other day but found no advantages over ABCs. In fact, failing to implement an ABC's interface is a 'compile-time' error, which is impossible to miss. Using protocols and mypy would be a soft-fail in comparison, where code runs but can fall flat at runtime still, if mypy is simply ignored/forgotten (it's optional).
I guess implementing multiple protocols (interfaces in other languages like C#) is possible and more awkward using ABCs?
- saila 4y agoThere's some info in the PEP for protocols about their advantages versus other approaches: https://peps.python.org/pep-0544/#rationale-and-goals https://peps.python.org/pep-0544/#rationale-and-goals https://peps.python.org/pep-0544/#existing-approaches-to-structural-subtyping https://peps.python.org/pep-0544/#existing-approaches-to-str... As to mypy being optional, it's easy enough to make it required via git hooks and/or CI. If your process doesn't make this easy for mypy or any other tool (e.g. formatting), I'd wager there are more fundamental issues.