]> granicus.if.org Git - python/commitdiff
#2358: add py3k warning to sys.exc_clear().
authorGeorg Brandl <georg@python.org>
Fri, 21 Mar 2008 20:11:46 +0000 (20:11 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 21 Mar 2008 20:11:46 +0000 (20:11 +0000)
Lib/test/test_py3kwarn.py
Misc/NEWS
Python/sysmodule.c

index 2b54ee1cf4bcba3981e33e92160915877c5ab4dc..aaa16231b940b30feee8f5e66b8dbb053c19e8b1 100644 (file)
@@ -94,6 +94,11 @@ class TestPy3KWarnings(unittest.TestCase):
         with catch_warning() as w:
             self.assertWarning(sorted(lst, cmp), w, expected)
 
+    def test_sys_exc_clear(self):
+        expected = 'sys.exc_clear() not supported in 3.x. Use except clauses.'
+        with catch_warning() as w:
+            self.assertWarning(sys.exc_clear(), w, expected)
+
 def test_main():
     run_unittest(TestPy3KWarnings)
 
index 70409364ec840864290d97a6c1207c647b4223cf..a581247a0a870958a21040a1d05c0291e103cc4b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -11,6 +11,8 @@ What's New in Python 2.6 alpha 2?
 
 Core and builtins
 -----------------
+- Issue #2358: Add a Py3k warning on sys.exc_clear() usage.
 
 - Issue #2400: Allow relative imports to "import *".
 
index 8e27844eaa2571ef54234544024a8ab16d1b498e..385969f8e2b125a85adc0010636af16fdbdf1552 100644 (file)
@@ -169,8 +169,16 @@ clause in the current stack frame or in an older stack frame."
 static PyObject *
 sys_exc_clear(PyObject *self, PyObject *noargs)
 {
-       PyThreadState *tstate = PyThreadState_GET();
+       PyThreadState *tstate;
        PyObject *tmp_type, *tmp_value, *tmp_tb;
+
+       if (Py_Py3kWarningFlag &&
+           PyErr_Warn(PyExc_DeprecationWarning,
+                      "sys.exc_clear() not supported in 3.x. "
+                      "Use except clauses.") < 0)
+               return NULL;
+
+       tstate = PyThreadState_GET();
        tmp_type = tstate->exc_type;
        tmp_value = tstate->exc_value;
        tmp_tb = tstate->exc_traceback;