[Python-Dev] type categories

Oren Tirosh oren-py-d@hishome.net
Sat, 24 Aug 2002 19:59:07 +0300

On Sat, Aug 24, 2002 at 11:15:56AM -0400, Jeremy Hylton wrote:
> Good point, Oren.  We now have two requirements for interfaces that
> are different than the standard inheritance mechanism.  It should be
> possible to:     
>   - inherit from a class without implementing that class's interfaces
>   - declare that a class implements an interface outside the class
>     statement
> It's harder to support the second requirement using the current
> inheritance mechanism.

I want to go a step further.  I don't want to declare that a class 
implements an interface outside the class statement. I don't want to 
declare *anything* about classes.

My approach centers on the user of the class rather than the provider.
The user can declare what he *expects* from the class and the inteface 
checking will verify that the class meets these requirements. In a way 
this is what you already do in Python - you use the object and if it 
doesn't meet your expectations it raises an exception. Exceptions are
raised for both bad form and bad content. Bad content will still trigger
an exception when you try to use it but bad form can be detected much

See http://www.tothink.com/python/predicates

I originally developed this for rulebases in security applications. I am
now porting it to Python and cleaning it up. I think it should be an
effective way to write assertions about the form of class objects based on
methods, call signatures, etc.  If/when type checking is added to Python
it should also be possible to specify specific types for arguments and
return values.