Marc D.M. wrote: > On Thu, 2006-09-07 at 13:28 -0500, Adrian Holovaty wrote: >> On 9/7/06, Michael Spencer <[EMAIL PROTECTED]> wrote:
>> >>> If you're really hunting for speed, there is a significant boost available >>> in >>> the common special case of a python function curried with one positional >>> argument. In this case, you can [ab]use the method binding machinery, e.g.: >>> [...] >>> This is about twice as fast as curry2 for the case of a python function >>> curried >>> with one argument. It also offers better introspection than either curry1 or >>> curry2, since the original signature is preserved. It's a bigger change >>> than >>> the curry2 though, since it changes the type of the curry from function to >>> bound >>> method. >> I was with you until "it changes the type of the curry from function >> to bound method." How does it do that? >> >> Adrian > > I think what's going on is that in the try : except clause, the return > value is the actual bound method, retrieved using the __get__ > magic-method. > Yep. > And it doesn't work very well that way either. I've tried Michael's > method and the whole house comes tumbling down. See traceback below when > trying to load a flatpage. > [snip...house falling down] I should have included a guard to ensure that the shortcut applies only to functions, not bound methods. Something like the following... import types def curry3(_curried_fct, *args, **kwargs): if len(args) == 1 and type(_curried_fct) is types.FunctionType: # Special case where we try to abuse the descriptor try: return _curried_fct.__get__(args[0]) except AttributeError: # built-ins fail - handle them in the normal way pass def _curried(*moreargs, **morekwargs): return _curried_fct (*(args+moreargs), **dict(kwargs, ** morekwargs)) return _curried This is still just a sketch, but my own django app runs with curry defined this way. Michael --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---