Re: How to avoid () when writing a decorator accepting optional arguments?

2011-06-17 Thread bruno.desthuilli...@gmail.com
On Jun 11, 10:28 pm, Ian Kelly ian.g.ke...@gmail.com wrote: Since there is no way to distinguish the two cases by the arguments, def deprecated(func=None, replacement=None): if replacement: # handle the case where a replacement has been given elif func: # handle the case

Re: How to avoid () when writing a decorator accepting optional arguments?

2011-06-17 Thread Ian Kelly
On Fri, Jun 17, 2011 at 4:27 AM, bruno.desthuilli...@gmail.com bruno.desthuilli...@gmail.com wrote: On Jun 11, 10:28 pm, Ian Kelly ian.g.ke...@gmail.com wrote: Since there is no way to distinguish the two cases by the arguments, def deprecated(func=None, replacement=None):    if replacement:

Re: How to avoid () when writing a decorator accepting optional arguments?

2011-06-17 Thread bruno.desthuilli...@gmail.com
On Jun 17, 3:53 pm, Ian Kelly ian.g.ke...@gmail.com wrote: That works, but I would be concerned about forgetting to specify the argument by keyword (snip funny side effect description)  Also, as in my suggestion, it doesn't seem like a big improvement to have to type out replacement= when

Re: How to avoid () when writing a decorator accepting optional arguments?

2011-06-17 Thread Ethan Furman
Giampaolo Rodolà wrote: I've written this decorator to deprecate a function and (optionally) provide a callable as replacement I can see providing the replacement function so that you can say, for example, you are calling a deprecated function -- function xyz is the replacement. If your

Re: How to avoid () when writing a decorator accepting optional arguments?

2011-06-16 Thread zeekay
I wrote a little library that does this a couple weeks ago, it's on pypi: http://pypi.python.org/pypi/Decorum/. It's pretty simple, the last example illustrates how to do what you want. After thinking about it though, I think it's probably not a great idea to allow the parenthesis to be omitted.

How to avoid () when writing a decorator accepting optional arguments?

2011-06-11 Thread Giampaolo Rodolà
I've written this decorator to deprecate a function and (optionally) provide a callable as replacement def deprecated(repfun=None): A decorator which can be used to mark functions as deprecated. Optional repfun is a callable that will be called with the same args as

Re: How to avoid () when writing a decorator accepting optional arguments?

2011-06-11 Thread Ian Kelly
On Sat, Jun 11, 2011 at 1:27 PM, Giampaolo Rodolà g.rod...@gmail.com wrote:    @deprecated()    def foo():        return 0 This is equivalent to: foo = deprecated()(foo)    @deprecated(some_function)    def foo():        return 0 foo = deprecated(some_function)(foo)    @deprecated    

Re: How to avoid () when writing a decorator accepting optional arguments?

2011-06-11 Thread Terry Reedy
On 6/11/2011 3:27 PM, Giampaolo Rodolà wrote: I've written this decorator to deprecate a function and (optionally) provide a callable as replacement def deprecated(repfun=None): A decorator which can be used to mark functions as deprecated. Optional repfun is a callable