Skip to content

Commit 1f12b38

Browse files
Merge #24
24: Warn for exception: move warning to ceval r=ltratt a=nanjekyejoannah This replaces the old PR: #12 Moved the warning to ceval. I removed the three component warning because it was committed in an earlier PR here: #14 Co-authored-by: Joannah Nanjekye <[email protected]>
2 parents 50b46c5 + ee36297 commit 1f12b38

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Lib/test/test_py3kwarn.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ class C:
258258
c = C()
259259
with check_py3k_warnings() as w:
260260
self.assertWarning(dir(c), w, expected)
261+
262+
def test_sys_exc_info(self):
263+
expected = 'sys.exc_info() not supported in 3.x: use except clauses.'
264+
with check_py3k_warnings() as w:
265+
self.assertWarning(sys.exc_info(), w, expected)
266+
267+
def test_exception_iterable(self):
268+
def helperftn():
269+
try:
270+
pass
271+
except RuntimeError as (num, message):
272+
return None
273+
expected = "Iterable exceptions are not supported in 3.x: access the arguments through the 'args' attribute instead"
274+
with check_py3k_warnings() as w:
275+
self.assertWarning(helperftn, w, expected)
276+
261277

262278
def test_softspace(self):
263279
expected = 'file.softspace not supported in 3.x'

Python/ceval.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4870,7 +4870,11 @@ cmp_outcome(int op, register PyObject *v, register PyObject *w)
48704870
CANNOT_CATCH_MSG, 1);
48714871
if (ret_val < 0)
48724872
return NULL;
4873-
}
4873+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
4874+
"Iterable exceptions are not supported in 3.x"
4875+
"access the arguments through the 'args' attribute instead", 1) < 0)
4876+
return NULL;
4877+
}
48744878
}
48754879
}
48764880
else {

Python/sysmodule.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ PyDoc_STRVAR(excepthook_doc,
149149
static PyObject *
150150
sys_exc_info(PyObject *self, PyObject *noargs)
151151
{
152+
if (Py_Py3kWarningFlag) {
153+
if (PyErr_WarnExplicit_WithFix(PyExc_Py3xWarning,
154+
"sys.exc_info() not supported in 3.x",
155+
"use except clauses", NULL, NULL,
156+
NULL, NULL)) {
157+
return NULL;
158+
}
159+
}
152160
PyThreadState *tstate;
153161
tstate = PyThreadState_GET();
154162
return Py_BuildValue(

0 commit comments

Comments
 (0)