Yet Another PEP: Interface Adapter Mechanism __adapt__

Rainer Deyke root at rainerdeyke.com
Wed Mar 21 11:42:34 EST 2001


"Clark C. Evans" <cce at clarkevans.com> wrote in message
news:Pine.LNX.4.21.0103210418490.21377-100000 at clarkevans.com...
>     def adapt(obj,ident, options =  None):
>         global check_base
>         def check_base(bas,cmp):
>             if bas == cmp: return 1
>             for base in bas.__bases__:
>                 if check_base(base,cmp): return 1
>             return 0
>         if hasattr(obj, '__adapt__'):
>             retval = obj.__adapt__(ident)
>         if retval == None:
>             if check_base(obj.__class__,ident):
>                 retval = obj
>         # options flag used to enable:
>         #   - reverse lookup via ident (future PEP) goes here?
>         #   - signature based lookup (future PEP) goes here?
>         #   - automatic signature checking (future PEP) goes here?
>         return retval

This 'check_base' stuff is a mess.  "A is an instance of a superclass of B"
does not imply "B implements interface A".  I also don't see why 'ident'
should be a class instance instead of just a class or a new built-in type.
What functionality does 'ident' provide?  How are extension types supported?


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list