[Python-3000] Abilities / Interfaces
Bill Janssen
janssen at parc.com
Thu Nov 23 00:59:55 CET 2006
> I'm concerned about the additional wrinkle where there is a library
> that calls the factory to produce A's and then turns around and passes
> them on to *another* library. Now the other can deal with A's but has
> recently been upgraded so that it works much better with B's; but it
> doesn't know that A's are fine B's already. ideally, there'd be an
> indirection in there somewhere that would let us insert a conversion
> from A to B; but if there isn't, it would be nice to be able to poke
> into A a marker indicating that it also supports B.
There's a dangling "it" in there which I'm not sure I have the right
antecedent for. Let's see if I've got this straight :-).
class B (A):
...
def library_1_code():
...
value_A = factory_which_really_produces_Bs()
library_2_which_works_much_better_with_Bs(value_A)
...
Isn't the marker already implicit? Does it matter that the first
library only thinks of the A interface for the value? Or are you just
looking for a new built-in like
def markas (i, interface_class):
if not isinstance(i, interface_class):
class X (i.__class__, interface_class):
pass
i.__class__ = X
interface_class.__init__(i)
return i
?
> Somehow that looks nicer with interfaces than with ABCs.
I think I've lost track of the difference.
Bill
More information about the Python-3000
mailing list