3 ms·
How does this differ in practice from typing.Protocol?
by orf 5y ago
How does this differ in practice from typing.Protocol?
- xrudelis 5y agoIt 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!
- heavyset_go 5y ago> 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.
- BerislavLopac 5y agoProtocols 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.