[Python-checkins] r62749 - in python/trunk: Lib/test/test_warnings.py Python/_warnings.c

brett.cannon python-checkins at python.org
Tue May 6 06:37:31 CEST 2008


Author: brett.cannon
Date: Tue May  6 06:37:31 2008
New Revision: 62749

Log:
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.


Modified:
   python/trunk/Lib/test/test_warnings.py
   python/trunk/Python/_warnings.c

Modified: python/trunk/Lib/test/test_warnings.py
==============================================================================
--- python/trunk/Lib/test/test_warnings.py	(original)
+++ python/trunk/Lib/test/test_warnings.py	Tue May  6 06:37:31 2008
@@ -225,6 +225,8 @@
                 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")

Modified: python/trunk/Python/_warnings.c
==============================================================================
--- python/trunk/Python/_warnings.c	(original)
+++ python/trunk/Python/_warnings.c	Tue May  6 06:37:31 2008
@@ -445,10 +445,8 @@
 
     /* 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;


More information about the Python-checkins mailing list