[Python-checkins] cpython (3.1): Issue #10756: atexit normalizes the exception before displaying it. Patch by

victor.stinner python-checkins at python.org
Sun May 15 19:02:39 CEST 2011


http://hg.python.org/cpython/rev/461e37a60187
changeset:   70148:461e37a60187
branch:      3.1
parent:      70137:945ca78c38b1
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Sun May 15 18:57:44 2011 +0200
summary:
  Issue #10756: atexit normalizes the exception before displaying it. Patch by
Andreas Stührk.

Backport a fix already applied to Python 3.2+ (4a82be47a948 + 5060a92a8597).

files:
  Lib/test/test_atexit.py |  8 ++++++++
  Misc/NEWS               |  3 +++
  Modules/atexitmodule.c  |  1 +
  3 files changed, 12 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py
--- a/Lib/test/test_atexit.py
+++ b/Lib/test/test_atexit.py
@@ -65,6 +65,14 @@
 
         self.assertRaises(TypeError, atexit._run_exitfuncs)
 
+    def test_raise_unnormalized(self):
+        # Issue #10756: Make sure that an unnormalized exception is
+        # handled properly
+        atexit.register(lambda: 1 / 0)
+
+        self.assertRaises(ZeroDivisionError, atexit._run_exitfuncs)
+        self.assertIn("ZeroDivisionError", self.stream.getvalue())
+
     def test_stress(self):
         a = [0]
         def inc():
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -72,6 +72,9 @@
 Library
 -------
 
+- Issue #10756: atexit normalizes the exception before displaying it. Patch by
+  Andreas Stührk.
+
 - Issue #8650: Make zlib module 64-bit clean. compress(), decompress() and
   their incremental counterparts now raise OverflowError if given an input
   larger than 4GB, instead of silently truncating the input and returning
diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c
--- a/Modules/atexitmodule.c
+++ b/Modules/atexitmodule.c
@@ -72,6 +72,7 @@
             PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
             if (!PyErr_ExceptionMatches(PyExc_SystemExit)) {
                 PySys_WriteStderr("Error in atexit._run_exitfuncs:\n");
+                PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb);
                 PyErr_Display(exc_type, exc_value, exc_tb);
             }
         }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list