[Python-ideas] A proper way to bring real interfaces to Python

Serge Matveenko s at matveenko.ru
Mon May 6 11:30:43 EDT 2019


On Mon, May 6, 2019 at 5:33 PM Ivan Levkivskyi <levkivskyi at gmail.com> wrote:
>
> On Mon, 6 May 2019 at 03:23, Serge Matveenko <s at matveenko.ru> wrote:
>>
>> On Sun, May 5, 2019 at 8:23 PM Stephen J. Turnbull
>> <turnbull.stephen.fw at u.tsukuba.ac.jp> wrote:
>> >
>> > Serge Matveenko writes:
>> >
>> >  > So, I would like to propose adding a third main object called
>> >  > `interface` in addition to `object` and `type` and to use it to define
>> >  > interface objects. Such interfaces could then be used in the class
>> >  > definition in the following way.
>> >
>> > How does this compare to existing technology such as zope.interface?
>> > Why do you want it to behave differently where it does?
>>
>> Also, `strict-interfaces` provides typing annotations support and
>> could be easily be adopted in conjunction with PEP 544.
>
>
> I am not sure why one would need another special base class to enforce checking implementations statically.
> Currently mypy can already enforce implementations of Protocols/ABCs at instantiation time. I can imagine one can just add a flag
> (like --early-implementations) without other changes.

This another special base class is not for static checks. This is
about checks at module execution time and generally as Steven has
pointed out at class creation time. This allows to build interfaces
using dynamic factories for instance and then enforce the
implementation.
I see how mypy, type annotations and protocols are other useful links
in the same chain along with interfaces but I cannot see how mypy is
the replacement for the later.


More information about the Python-ideas mailing list