[Types-sig] Interface PEP

Paul Prescod paulp@ActiveState.com
Mon, 19 Mar 2001 01:22:21 -0800

[feel free to keep insisting. you are helping to sharpen my thinking on
these issues]

Samuele Pedroni wrote:
> Hi.
> All interfaces are domain but at least at the beginning of our
> discussion not all domains were interfaces, one could define
> the domain Prime. 

I agree with this. The procedural definition is always more general than
the declarative ones because you have the full power of Python available
for your declaration.

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

Fair enough.

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

Perhaps there needs to be a "strict" modifier to declarations that says
whether merely checking for methods is sufficient or whether an explicit
declaration is required. It should probably be up to a specific function
whether it wants to use the first method of checking, or the second, or

On the other hand, perhaps it is just extra complexity. If you wanted
strict checking, wouldn't it be easy to implement an __check__ method
that checked both the __interfaces__ AND the actual signature? Or you
could require a method name like def __supports_readability__(): pass.

Python already has types and classes. I'm adding something that you call
protocols. Michel is adding something that he calls interfaces. It makes
sense to have type declarations that reference all four. It is important
to me to simplify this model...

Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook