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

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Fri Jun 17 06:27:37 EDT 2011


On Jun 11, 10:28 pm, Ian Kelly <ian.g.ke... at 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 where no replacement has been given
    else:
       raise ValueErrorOrSomethingLikeThis()


@deprecated(replacement=other_func):
def some_func(args):
    # code here

@deprecated
def another_func(args):
    # code here


My 2 cents...



More information about the Python-list mailing list