[Types-sig] Type equivalence

Paul Prescod paulp@ActiveState.com
Wed, 14 Mar 2001 23:41:07 -0800


Marcin 'Qrczak' Kowalczyk wrote:
> 
> ...
> > We may need to add a boolean type to Python.
> 
> I agree. But I'm afraid that if Guido wanted it, he would add it
> earlier.

It would be easy enough to add it but it depends on whether we want the
definition of 

	lambda obj: obj in (0, 1)

or the definition that "every object can be used as a boolean":

	lambda obj: "you betcha!"

> Indeed. The system must not require ReadableFile to know about
> MustHaveRead. Let's not repeat Java's mistakes.

The system as we have been designing it does not have a problem with
this sort of thing. It works like this:

 1. First it checks if an object *declares* an interface.

If it can't find that it falls back to:

 2. Checking the signature of the objects.

In some future "strict types" mode, this sort of "passing off" might
issue a warning. I claim, though, that it won't arise that much in
practice. It is going to be very rarely the case that two different
modules define methods with the SAME name and the SAME semantic without
some reference to a common defining document or interface. That defining
thing is the type that the other two are subtypes of.

In other words, the only reason you can safe pass around things with
.read() to modules from company A and B without a problem is because
Guido defined what read() means a long time ago informally. I'd be
interested to hear about an example where the same method name arose
with the same signature and semantics completely independently.

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