best way to create warning for obsolete functions and call new one
rosuav at gmail.com
Mon Mar 26 23:50:35 CEST 2012
On Tue, Mar 27, 2012 at 7:26 AM, Gelonida N <gelonida at gmail.com> wrote:
> One option I though of would be:
> def obsolete_func(func):
> def call_old(*args, **kwargs):
> print "func is old psl use new one"
> return func(*args, **kwargs)
> return call_old
> def get_time(a='high'):
> return a + 'noon'
That's a reasonable idea. Incorporate Dan's suggestion of using
You may want to try decorator syntax:
return a + 'noon'
That won't raise DeprecationWarning, though. It's a very simple
assignment. The was() internal function could be enhanced to do a bit
more work, but I'm not sure what version of Python you're using and
what introspection facilities you have. But if you're happy with the
old versions coming up with (*args,**kwargs) instead of their
parameter lists, it's not difficult:
# raise DeprecationWarning
I've never actually used the Python warnings module, but any line of
code you fill in at the comment will be executed any time the old name
is used. In any case, it's still used with the same convenient
decorator. You could even unify multiple functions under a single new
Hope that helps!
More information about the Python-list