[Python-3000] Adaptation [was:Re: Iterators for dict keys, values, and items == annoying :)]
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Apr 4 04:06:10 CEST 2006
Nick Coghlan wrote:
> In this case, it makes far more sense to me to move the adapter
> registration out to the individual protocols.
That would alleviate some of my concerns as well. This
seems more Pythonic: Namespaces are one honking... etc.
> In a glorious fit of self-referentiality, one of the first things needed by
> such an approach would be a protocol for the protocol interface that allowed
> other protocol objects to register themselves as implementing it. This would
> then allow the ever popular generic adaptation function to be written as:
>
> def adapt(obj, target_protocol):
> return Protocol.adapt(target_protocol).adapt(obj)
Surely the protocol protocol would be well-known enough
that other protocols would simply be duck-typed to it,
rather than having to be adapted to it?
Also I prefer the idea of the protocol object being
callable, so you just do
target_protocol(obj)
to do an adaptation.
--
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | Carpe post meridiam! |
Christchurch, New Zealand | (I'm not a morning person.) |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Python-3000
mailing list