[Types-sig] Interfaces API

Paul Prescod paulp@ActiveState.com
Thu, 15 Mar 2001 14:06:21 -0800


Michel Pelletier wrote:
> 
>...
> 
> Well, i'm not sure how yours works.  Is there a description somewhere?

There's the code. :) A more formal description will come later.

http://www.prescod.net/pytypes/os.py
http://www.prescod.net/pytypes/typecheck.py

> I'm wondering if you're interface objects describe their elements are
> attributes of that object.  

No, not yet. I see that as a feature I would add in a merger with your
interface objects.

> For example, in your model:
> 
> interface Foo:
>   def bar():
>     pass
> 
> Does this make a 'Foo.bar'?  

I have no such syntax. I am happy to defer to your syntax. All I have
are __check__ methods. If your objects can export some ability to verify
that an instance could reasonably conform (in signature at least) to an
interface, you can call it __check__ and we will be in sync. Or I could
call mine implementedBy but I don't think that will fly.

>...
> But checking for the right number of names, methods, parameters, and even
> their types, is only a minor Java-esque win.  There's certainly no
> guarantee that the implementation will work in any way at all the way its
> interface describes, and no way to test that quickly.  

One of the constantly repeated requirements of the Python community
(e.g. Barry Warsaw's post from a few days ago) is that if an object
*looks like a file* it should be allowed to pass as a file through type
checks.

http://mail.python.org/pipermail/types-sig/2001-March/001198.html

> Anyway, about your second point, we have the complete opposite philosophy:
> run time checking is of lesser interest to us.  Flexible, rich
> introspection for tools and programmers to address the stated goals in the
> PEP is our main focus.  Not run time checking.

In that case I wouldn't really support a new syntactic element. You
could do it all in strings and it would be clearer to everyone that
there are no real runtime implications (other than introspection). Heck,
you could use XML documents with hyperlinks. :)

I think that using the word interface for something that has no
type-checking connotation will be confusing to those coming from every
other language and OO system such as Java, COM, CORBA, XPCOM, etc.

You'd be better off calling them "contracts" or "protocols".

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