mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 00:14:35 +03:00
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.
This commit is contained in:
parent
934b9df7b4
commit
9e2713890f
@ -1044,15 +1044,21 @@ class ui(object):
|
||||
'''
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user