# HG changeset patch # User Pierre-Yves David # Date 1449385533 28800 # Node ID 82910fdc216f1f1ec1345819d15a63934ef5690b # Parent 5d5b98346fc2959d0945f93e987e331de009dfa7 ui: add a 'stacklevel' argument to 'develwarn' This allows helper functions (like deprecation warning) to prepare a devel warning for higher up in the stack. The argument is named after the one in the Python's 'warning,warn' function. diff -r 5d5b98346fc2 -r 82910fdc216f mercurial/ui.py --- a/mercurial/ui.py Sun Dec 06 14:28:35 2015 +0900 +++ b/mercurial/ui.py Sat Dec 05 23:05:33 2015 -0800 @@ -1044,15 +1044,21 @@ ''' return msg - def develwarn(self, msg): - """issue a developer warning message""" + def develwarn(self, msg, stacklevel=1): + """issue a developer warning message + + Use 'stacklevel' to report the offender some layers further up in the + stack. + """ msg = 'devel-warn: ' + msg + stacklevel += 1 # get in develwarn if self.tracebackflag: - util.debugstacktrace(msg, 2, self.ferr, self.fout) + util.debugstacktrace(msg, stacklevel, self.ferr, self.fout) else: curframe = inspect.currentframe() calframe = inspect.getouterframes(curframe, 2) - self.write_err('%s at: %s:%s (%s)\n' % ((msg,) + calframe[2][1:4])) + self.write_err('%s at: %s:%s (%s)\n' + % ((msg,) + calframe[stacklevel][1:4])) class paths(dict): """Represents a collection of paths and their configs.