[Python-Dev] PEP 544: Protocols - second round (original) (raw)

Ivan Levkivskyi levkivskyi at gmail.com
Sun May 28 11:27:33 EDT 2017


On 28 May 2017 at 16:13, Kevin Conway <kevinjacobconway at gmail.com> wrote:

> Some of the possible options for the title are It seems like you're talking about something most other languages would refer to as "Interfaces". What is unique about this proposal that would call for not using the industry standard language?

Well, I would say there is no "industry standard language" about structural subtyping. There are interfaces, protocols, traits, mixins, typeclasses, roles, and probably some other terms I am not aware of - all with subtly different semantics in different languages. There are several reasons why we use term protocol and not interface. Two important reasons for me are:

Type-hints should not have runtime semantics, beyond those that they have as classes > lots of code uses isinstance(obj, collections.abc.Iterable) and similar checks with other ABCs Having interfaces defined as something extended from abc doesn't necessitate their use at runtime, but it does open up a great deal of options for those of us who want to do so. I've been leveraging abc for a few years now to implement a lightweight version of what this PEP is attempting to achieve

IIUC this is not the main goal of the PEP, the main goal is to provide support/standard for static structural subtyping. Possibility to use protocols in runtime context is rather a minor bonus that exists mostly to provide a seamless transition for projects that already use ABCs.

-- Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20170528/d46ea0b7/attachment.html>



More information about the Python-Dev mailing list