Fix a bug in the handling of the stacklevel argument in warnings.warn() where

the stack was being unwound by two levels instead of one each time.
This commit is contained in:
Brett Cannon 2008-05-06 04:37:31 +00:00
parent 0b7f77847a
commit e3dcb01bfc
2 changed files with 3 additions and 3 deletions

View File

@ -225,6 +225,8 @@ class WarnTests(unittest.TestCase):
self.assertEqual(os.path.basename(w.filename), "test_warnings.py")
warning_tests.outer("spam6", stacklevel=2)
self.assertEqual(os.path.basename(w.filename), "warning_tests.py")
warning_tests.outer("spam6.5", stacklevel=3)
self.assertEqual(os.path.basename(w.filename), "test_warnings.py")
warning_tests.inner("spam7", stacklevel=9999)
self.assertEqual(os.path.basename(w.filename), "sys")

View File

@ -445,10 +445,8 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
/* Setup globals and lineno. */
PyFrameObject *f = PyThreadState_GET()->frame;
while (--stack_level > 0 && f != NULL) {
while (--stack_level > 0 && f != NULL)
f = f->f_back;
--stack_level;
}
if (f == NULL) {
globals = PyThreadState_Get()->interp->sysdict;