mirror of https://github.com/python/cpython
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:
parent
0b7f77847a
commit
e3dcb01bfc
|
@ -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")
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue