[Python-Dev] PEP 544: Protocols - second round

Guido van Rossum guido at python.org
Sun May 28 13:40:37 EDT 2017


On Sun, May 28, 2017 at 8:27 AM, Ivan Levkivskyi <levkivskyi at gmail.com>
wrote:

> 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:
> * The term protocol is already de-facto standard in Python for things like
> sequence protocol, iterator protocol,
>   descriptor protocol, etc.
> * Protocols are very different from Java interfaces in one important
> aspect: they don't require explicit
>   declaration of implementation, they are mainly oriented on duck-typing.
> Maybe we need to add a short section to rejected ideas?
>

If you feel like it.

Regarding the title, I'd like to keep the word Protocol in the title too,
so I'd go with "Protocols: Structural subtyping (duck typing)" -- hope
that's not too long to fit in a PEP title field.


> > 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.
>

Is something like this already in the PEP? It deserves attention in one of
the earlier sections.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170528/61c4fd96/attachment.html>


More information about the Python-Dev mailing list