Commits

Brett Cannon  committed 2f351fa

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.

  • Participants
  • Parent commits 7106ca8
  • Branches legacy-trunk

Comments (0)

Files changed (2)

File Lib/test/test_warnings.py

                 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")

File Python/_warnings.c

 
     /* 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;