[Python-Dev] PEP 246, redux

Nick Coghlan ncoghlan at iinet.net.au
Thu Jan 13 15:30:17 CET 2005


Phillip J. Eby wrote:
> Anyway, I'm at least +0 on dropping this; the reservation is just 
> because I don't think everybody else will agree with this, and don't 
> want to be appearing to imply that consensus between you and me implies 
> any sort of community consensus on this point.  That is, the adaptation 
> from "Alex and Phillip agree" to "community agrees" is noisy at best!  ;)

You seem to be doing a pretty good job of covering the bases, though. . .

Anyway, I'd like to know if the consensus I think you've reached is the one the 
pair of you think you've reached :)

That is, with A being our starting class, C being a target class, and F being a 
target interface, the legal adaptation chains are:
   # Class to class
   A->C
   # Class to interface, possibly via other interfaces
   A(->F)*->F

With a lookup sequence of:
   1. Check the global registry for direct adaptations
   2. Ask the object via __conform__
   3a. Check using isinstance() unless 2 raised LiskovViolation
   3b. Nothing, since object.__conform__ does an isinstance() check
   4. Ask the interface via __adapt__
   5. Look for transitive chains of interfaces in the global registry.

3a & 3b are the current differing answers to the question of who should be 
checking for inheritance - the adaptation machinery or the __conform__ method.

If classes wish to adapt to things which their parents adapt to, they must 
delegate to their parent's __conform__ method as needed (or simply not override 
__conform__). The ONLY automatic adaptation links are those that allow a subtype 
to be used in place of its parent type, and this can be overriden using 
__conform__. (FWIW, this point about 'adapting to things my parent can adapt to' 
by delegating in __conform__ inclines me in favour of option 3b for handling 
subtyping. However, I can appreciate wanting to keep the PEP free of proposing 
any changes to the core - perhaps mention both, and leave the decision to the BDFL?)

One question - is the presence of __adapt__ enough to mark something as an 
interface in the opinion of the adaptation machinery (for purposes of step 5)?

Second question - will there be something like __conformant__ and __conforming__ 
to allow classes and interfaces to provide additional information in the 
transitive search in step 5?

Or are both of these questions more in PEP 245 territory?

Cheers,
Nick.
Almost sent this to c.l.p by mistake . . .

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net


More information about the Python-Dev mailing list