Nicely done! I think it'd be useful to wrap this into a small library
and release it for people who want to use it, with a bit of narrative
documentation on its own for the PyPI front page.
One thing you may want to think about, is to have an option for delaying
the registration until configuration time, and use configuration
actions, so that you get conflict resolution and possibly easier debugging.
You could do that using martian. The package would need to be "grokked"
with a <grok:grok package="." /> directive, but don't let the word
"grok" put you off - there's nothing Grok-the-framework-specific about
Paul Wilson wrote:
> 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!
> Zope-Dev maillist - Zope-Dev@zope.org
> ** No cross posts or HTML encoding! **
> (Related lists -
> https://mail.zope.org/mailman/listinfo/zope )
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book
Zope-Dev maillist - Zope-Dev@zope.org
** No cross posts or HTML encoding! **
(Related lists -