[melbourne-pug] Coding idiom

Bill Birch birchb at tpg.com.au
Mon May 8 15:40:57 CEST 2006


On Fri, 5 May 2006 02:27 pm, Justin Warren wrote:

> Note that when I say "code that is temporarily deprecated", by renaming
> the method I have explicitly changed the API from containing the method
> as a public method to one that is indicated as for internal use. Such
> use will be accompanied by comments, and since ._xx() won't get
> inherited by import *, you won't know about it unless you go looking for
> it, and notice the comments. 99% of the time such code doesn't make it
> out of testing and won't be checked into the code repository.
>
> Truly deprecated code raises a *mumble*Deprecated warning.
How about yet another decorator?

def deprecated(f):
    def new_f(*args, **kwds):
        print "warning: deprecated function", f.func_name
        return f(*args, **kwds)
    new_f.func_name = f.func_name
    return new_f

@deprecated
def lepard(a, *args, **kwargs): 
    print a, args, kwargs

>>> lepard(1,2,3, four=4)
warning: deprecated function lepard
1 (2, 3) {'four': 4}

-- 
http://billbirch.wordpress.com/


More information about the melbourne-pug mailing list