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