[Zope-dev] Zope3 and Generic Functions

Paul Wilson paulalexwilson at gmail.com
Fri Jan 1 12:43:30 EST 2010

Hi there,

I've been really getting my head around Zope3 and adaption lately for
a talk for my local Python usergroup. I've read quite a bit on the
topic, but of particular interest was the adapter vs. generic function
debate that's been doing the rounds over the last few years. See Guido
van Rossum's article here:


where he concludes that generic functions are more general and useful.
Further, we have Ian Bicking's Zope 3 critique where, he argues that
generic functions are generally better and Martijn Faassen's comment:

"I agree by the way that generic methods are interesting and we should
be investigating how they fit in a Zope 3 context."

There is a clear relationship between the two, and after some
brainstorming with Chris McDonough on the Zope IRC channel, I've been
able to write an @generic(TypeA, TypeB, ... , TypeN) decorator that
uses the Zope component registry to supply such behaviour. It's become
clear to me that named multiadapters are essentially the same concept
as generic functions, and in a Zope context, are actually more
powerful because you can specify *interfaces* as well as concrete
types as part of the function's type-signature: @generic(IFoo, IBar,
TypeA, TypeB, ...). I don't know if this relationship is already known
in the Zope world, and if people are already doing this? Is there any
value in something like this?

It's pretty 'deep' stuff, so I've written a tutorial (Chris's idea)
that goes through the thought process towards writing the generic
function decorator with Zope tools - please find attached. We think it
might make a nice (supplementary) addition to upcoming zope.component
narrative documentation (there is upcoming documentation... right?).
To confirm the idea I wrote a basic little script too, which I've
attached also. You can see that @generic works with types, interfaces
or both - thanks to the zope.component machinery.

Any thoughts would be great!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: generic_functions_zca.rst
Type: application/octet-stream
Size: 12538 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20100101/def73c8f/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: genericfuncs.py
Type: text/x-python
Size: 1471 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20100101/def73c8f/attachment.py 

More information about the Zope-Dev mailing list