[Python-Dev] PEP 246 - concrete assistance to developers of new
adapter classes
Alex Martelli
aleax at aleax.it
Fri Jan 21 14:29:04 CET 2005
On 2005 Jan 21, at 14:02, Nick Coghlan wrote:
> Phillip's monkey-typing PEP (and his goal of making it easy to write
> well behaved adapters) got me wondering about the benefits of
> providing an adaptation. Adapter class that could be used to reduce
> the boiler plate required when developing new adapters. Inheriting
> from it wouldn't be *required* in any way - doing so would simply make
> it easier to write a good adapter by eliminating or simplifying some
> of the required code. Being written in Python, it could also serve as
> good documentation of recommended adapter behaviour.
>
> For instance, it could by default preserve a reference to the original
> object and use that for any further adaptation requests:
>
> class Adapter(object):
> def __init__(self, original):
> self.original = original
>
> def __conform__(self, protocol):
> return adapt(self.original, protocol)
>
> Does anyone else (particularly those with PEAK and Zope interface
> experience) think such a class would be beneficial in encouraging good
> practices?
Yes, there was something just like that in Nevow (pre-move to the zope
interfaces) and it sure didn't hurt.
Alex
More information about the Python-Dev
mailing list