From e3dcb01bfc6bd14da865b0f28c3c9ad8181ab212 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Tue, 6 May 2008 04:37:31 +0000 Subject: 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. --- Lib/test/test_warnings.py | 2 ++ Python/_warnings.c | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index c854d7a..1b5ee32 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -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") diff --git a/Python/_warnings.c b/Python/_warnings.c index 3e7dda7..0e48675 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -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; -- cgit v0.12