Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22210 > unrolled thread

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

Started byGelonida N <gelonida@gmail.com>
First post2012-03-26 22:26 +0200
Last post2012-03-26 22:26 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  best way to create warning for obsolete functions and call new one Gelonida N <gelonida@gmail.com> - 2012-03-26 22:26 +0200

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

FromGelonida N <gelonida@gmail.com>
Date2012-03-26 22:26 +0200
Subjectbest way to create warning for obsolete functions and call new one
Message-ID<mailman.1018.1332793582.3037.python-list@python.org>
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
























[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web