News for hackers. Stuff that matters.
Re:Painless Decorators in Python by Leszek on Sunday November 03, 2013 @08:50AM (#6663167)
How does this compare to the decorator module?

https://pypi.python.org/pypi/decorator

Re:Painless Decorators in Python by Suor on Sunday November 03, 2013 @09:01AM (#6663197)
This handles decorators with arguments and makes a general case of passing same arguments to function as to wrapper less cluttered.
Re:Painless Decorators in Python by zb on Sunday November 03, 2013 @11:37AM (#6663773)
Decorators with arguments are much better handled by classes IMO. This does indeed appear to make that one (common) case of passing the function arguments through unchanged marginally simpler. But it makes every other case worse. Compare, for example:

    @decorator.decorator
    def int_args(func, *args):
        """Coerces any function arguments to ints"""
        return func(*map(int, args))
to your:

    @funcy.decorator
    def int_args(call):
        """Coerces any function arguments to ints"""
        return call._func(*map(int, call._args))
In the former case, everything is defined explicitly and it's clear that the function only accepts positional arguments. In the latter case, you're required to know the API of the library: that necessary objects are hidden behind the attributes call._func and call._args, and that the keyword arguments are silently discarded. It's an extremely leaky abstraction.

You probably think that passing 'self' to every method is boilerplate too, and arguably it is. But the Python philosophy is "explicit is better than implicit".

Re:Painless Decorators in Python by abecedarius on Sunday November 03, 2013 @10:58AM (#6663575)
It might help to show the same examples from that module's documentation, how they are similar or different.

I still don't understand this after a skim of your post, since one example has

    @decorator
    def some_decorator(func, args, kwargs):
while the next goes

    @decorator
    def some_decorator(call):
Does this introspect on the parameters of some_decorator?

FWIW I'm happy enough with https://github.com/darius/sketchbook/blob/master/misc/decora...

Re:Painless Decorators in Python by Suor on Sunday November 03, 2013 @11:02AM (#6663593)
The first part of a post is mere reasoning showing how I got to the actual interface I use. @decorator works with `call` not with `func, args, *kwargs`.
Re:Painless Decorators in Python by abecedarius on Sunday November 03, 2013 @11:05AM (#6663604)
Ah, OK. So there's no way to express an example that needs to get at func, etc.?

I think I'd separate out an @decorator that fixes the metadata on the returned function, and another one, using it, that makes a decorator that works on the call() interface.

Re:Painless Decorators in Python by yeukhon on Sunday November 03, 2013 @03:32PM (#6664896)
This is much more useful and more explicit than Sour's. I would rather use this old one.
Re:Painless Decorators in Python by bereft_orange on Sunday November 03, 2013 @12:03PM (#6663928)
the decorator module also preserves function signature, which is nice (check out the FunctionMaker class - it's crazy)