Mercurial > hg
comparison mercurial/ui.py @ 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 | 4dccc37b87bd |
children | f2cd240f2f7c |
comparison
equal
deleted
inserted
replaced
27273:5d5b98346fc2 | 27274:82910fdc216f |
---|---|
1042 ui.write(s, 'label') is equivalent to | 1042 ui.write(s, 'label') is equivalent to |
1043 ui.write(ui.label(s, 'label')). | 1043 ui.write(ui.label(s, 'label')). |
1044 ''' | 1044 ''' |
1045 return msg | 1045 return msg |
1046 | 1046 |
1047 def develwarn(self, msg): | 1047 def develwarn(self, msg, stacklevel=1): |
1048 """issue a developer warning message""" | 1048 """issue a developer warning message |
1049 | |
1050 Use 'stacklevel' to report the offender some layers further up in the | |
1051 stack. | |
1052 """ | |
1049 msg = 'devel-warn: ' + msg | 1053 msg = 'devel-warn: ' + msg |
1054 stacklevel += 1 # get in develwarn | |
1050 if self.tracebackflag: | 1055 if self.tracebackflag: |
1051 util.debugstacktrace(msg, 2, self.ferr, self.fout) | 1056 util.debugstacktrace(msg, stacklevel, self.ferr, self.fout) |
1052 else: | 1057 else: |
1053 curframe = inspect.currentframe() | 1058 curframe = inspect.currentframe() |
1054 calframe = inspect.getouterframes(curframe, 2) | 1059 calframe = inspect.getouterframes(curframe, 2) |
1055 self.write_err('%s at: %s:%s (%s)\n' % ((msg,) + calframe[2][1:4])) | 1060 self.write_err('%s at: %s:%s (%s)\n' |
1061 % ((msg,) + calframe[stacklevel][1:4])) | |
1056 | 1062 |
1057 class paths(dict): | 1063 class paths(dict): |
1058 """Represents a collection of paths and their configs. | 1064 """Represents a collection of paths and their configs. |
1059 | 1065 |
1060 Data is initially derived from ui instances and the config files they have | 1066 Data is initially derived from ui instances and the config files they have |