Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?



There'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/#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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: