best way to create warning for obsolete functions and call new one

G

Gelonida N

Hi,

I'm working on a module, which needs rather heavy renaming of functions
and methods
(naming style, change of functionality, understandability, orthography)

As these modules are used by quite some projects and as I do not want to
force everybody to rename immediately I just want to warn users, that
they call functions, that have been renamed and that will be obsoleted.



function example:
def get_thyme(a='high'): # old name
return a + 'noon'

# Should have been get_time(a, b)

method example:
class C():
def set_with(self, value=0): # should be set_width
self.width = value



What I basically want to do for each function is following:



def get_time(a='high'):
return a + 'noon'

def get_thyme(a):
# ideally the next line should display old and new function name
# but even with out I 'd be fine
logging.warning('obsolate function. please use the new function')
return get_time(a)




Assuming I want to rename loads of functions / metthods, what would be
the laziest option to so? (and have no run time penalty for the new call)



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

and

def get_time(a='high'):
return a + 'noon'

get_thyme = obsolete_func(get_time)

class C():
def set_width(self, value=0): # should be set_width
self.width = value

set_with = obsolete_func(set_width)



Another idea might be something like:

add_obsolete_functions(get_tyme=get_time, get_dayt=get_date)

Not sure though how to do this best for Classes

Thanks for any ideas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top