Mercurial > hg
changeset 27274:82910fdc216f
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.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Sat, 05 Dec 2015 23:05:33 -0800 |
parents | 5d5b98346fc2 |
children | f2cd240f2f7c |
files | mercurial/ui.py |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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.