Just a heads-up. In [1066] I committed
turbogears.genericfunctions.MultiorderGenericFunction class allowing
fine-tuning of resolution order.
when() and around() of a generic function defined in this manner take an
additional (optional, default 0) argument named order to define primary
method resolution order.
For example:
>>> from turbogears.genericfunctions import MultiorderGenericFunction
>>> from dispatch import generic
>>> @generic(MultiorderGenericFunction)
def foo(a, b):
pass
>>> @foo.when("a > b")
def foo_agtb(a, b):
print "I am first!"
>>> @foo.when("a > b", order=2)
def foo_agtb(a, b):
print "I hate being last :("
>>> foo(234,67)
I am first!
Order takes precedence before specificality:
>>> from dispatch import strategy
>>> @foo.when(strategy.default, order=-1)
def foo_superduper(next_method, a, b):
print "Better than the rest!"
return next_method(a, b)
>>> foo(234,67)
Better than the rest!
I am first!
To make it simple for the users, we should be the ones primarily worried
about order, defining rules with order > 0 where it makes sense to
override specialisations provided by TG (jsonify comes to mind).
See also:
http://trac.turbogears.org/turbogears/ticket/352
http://peak.telecommunity.com/DevCenter/CombiningResults
http://trac.turbogears.org/turbogears/browser/trunk/turbogears/genericfunctions.py
http://trac.turbogears.org/turbogears/browser/trunk/turbogears/tests/test_genericfunctions.py
Cheers,
Simon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears-trunk
-~----------~----~----~----~------~----~------~--~---