News for hackers. Stuff that matters.
Re:Show HN: Rust-Like Traits in Python by orf on Sunday November 21, 2021 @05:56PM (#29300609)
How does this differ in practice from typing.Protocol?
Re:Show HN: Rust-Like Traits in Python by xrudelis on Sunday November 21, 2021 @06:21PM (#29300797)
It looks to me like the goals with typing.Protocol are for static type checking. Whereas this module is intended both for interfaces (much like ABCs) and implementation re-use (see Rust's "blanket implementations"). These Traits could definitely be used in type annotation, and maybe there's a way to use typing.Protocol with them to aid static type checking in Python. I haven't tried static type checking in Python yet, but it sounds promising!
Re:Show HN: Rust-Like Traits in Python by heavyset_go on Sunday November 21, 2021 @07:47PM (#29301391)
> Whereas this module is intended both for interfaces (much like ABCs) and implementation re-use (see Rust's "blanket implementations")

That's the role typing.Protocol plays, as well. Protocols are like ABCs, but using structural typing.

Re:Show HN: Rust-Like Traits in Python by BerislavLopac on Sunday November 21, 2021 @08:37PM (#29301753)
Protocols can be used for runtime checks (isinstance), even for classes that are not explicitly annotated with them - that's the main point of structural subtyping.