[Types-sig] Interface PEP

Samuele Pedroni Samuele Pedroni <pedroni@inf.ethz.ch>
Thu, 15 Mar 2001 15:49:36 +0100 (MET)


Hi.

> Samuele, I agree with the vast majority of your analysis
<wink>
> but I'm not
> sure that the objects you call Protocol Domain Checkers and Interfaces
> are necessarily distinct. 
Maybe is just matter of viewpoint.

As fas as I have understood with Michel interfaces the idea is
that one declare explicitly when a class implements them
and you can check for that looking at the __implements__ attr,
which is setup at class definition time after enforcing
the "implements" decl through a check.

All interfaces are domain but at least at the beginning of our
discussion not all domains were interfaces, one could define
the domain Prime. So I don't know if the interface syntax can
be stretched to the point to deal with that too and Prime
is more an algorithmic-checkable property than something that an
input should declare to implement.

OTOH yes as far as protocol are concerned one 
could use the interface syntax to define them.
So we can the following:

   interface Readable:
     def read(size)

than there is an ambiguity problem when we should enforce the check:
with your new distinction __check__ vs. __implementedby__ should:


def grab(r: Readable)
  ...
  
test Readable.__check__(r) or Readable.__implementedby__(r).

I think we have agreed that for backw-compatibility and for python
tradition so far the right kind to check is the first (e.g. at least
for the std lib).
But a syntactic way to ask for checking the second would also be nice,
because one may require that an input really explicitly declare
an interface because this is the only way to be sure that
not also the signatures match but all the implicit requirements
that are associated with the interface are met.

We have the following distinction and inclusions:

interfaces < protocols < domains

So maybe we need a protocol syntax to define protocols, or a syntax
to distinguish the two kind of checks.
Domain can be defined just as singletons with the right method.

> 
> If you integrate protocols and interfaces then it makes sense for the
> integrated thingee to have an hierarchy.
> 
So the point is that I don't know to which extent is a clean thing
to integrate the two.


regards, Samuele Pedroni.