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
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