Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.04; 'ideally': 0.05; 'users,': 0.05; 'so?': 0.07; 'assuming': 0.09; 'be:': 0.09; 'module,': 0.09; 'rename': 0.09; 'subject:create': 0.09; 'print': 0.15; '**kwargs)': 0.16; '**kwargs):': 0.16; 'c():': 0.16; 'received:80.91': 0.16; 'received:80.91.229': 0.16; 'received:gmane.org': 0.16; 'received:list': 0.16; 'renaming': 0.16; 'warn': 0.16; 'def': 0.20; 'function': 0.22; 'header:User- Agent:1': 0.23; 'basically': 0.23; 'run': 0.26; 'idea': 0.26; 'quite': 0.26; 'classes': 0.27; 'fine': 0.27; 'following:': 0.27; 'class': 0.29; 'option': 0.32; 'hi,': 0.33; 'thanks': 0.34; 'subject:new': 0.35; '(and': 0.35; 'should': 0.35; 'force': 0.35; "i'm": 0.36; 'sure': 0.36; 'header:X-Complaints-To:1': 0.36; 'but': 0.36; 'some': 0.37; 'next': 0.38; 'something': 0.38; 'rather': 0.38; 'skip:l 20': 0.38; 'received:org': 0.38; 'to:addr :python-list': 0.39; 'how': 0.40; 'to:addr:python.org': 0.40; 'name': 0.61; 'call': 0.62; 'everybody': 0.72; 'heavy': 0.79; 'penalty': 0.84; 'subject:warning': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Gelonida N Subject: best way to create warning for obsolete functions and call new one Date: Mon, 26 Mar 2012 22:26:11 +0200 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: unicorn.dungeon.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.28) Gecko/20120313 Lightning/1.0b2 "" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 101 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332793582 news.xs4all.nl 6909 [2001:888:2000:d::a6]:52633 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22210 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