From 5a44424c5e6b9533b12773fadeaf436903ca855e Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 21 Mar 2008 20:11:46 +0000 Subject: [PATCH] #2358: add py3k warning to sys.exc_clear(). --- Lib/test/test_py3kwarn.py | 5 +++++ Misc/NEWS | 2 ++ Python/sysmodule.c | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_py3kwarn.py b/Lib/test/test_py3kwarn.py index 2b54ee1cf4b..aaa16231b94 100644 --- a/Lib/test/test_py3kwarn.py +++ b/Lib/test/test_py3kwarn.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index 70409364ec8..a581247a0a8 100644 --- 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 *". diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 8e27844eaa2..385969f8e2b 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -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;