Skip to content

Warn for exception: move warning to ceval #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_py3kwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,22 @@ class C:
c = C()
with check_py3k_warnings() as w:
self.assertWarning(dir(c), w, expected)

def test_sys_exc_info(self):
expected = 'sys.exc_info() not supported in 3.x: use except clauses.'
with check_py3k_warnings() as w:
self.assertWarning(sys.exc_info(), w, expected)

def test_exception_iterable(self):
def helperftn():
try:
pass
except RuntimeError as (num, message):
return None
expected = "Iterable exceptions are not supported in 3.x: access the arguments through the 'args' attribute instead"
with check_py3k_warnings() as w:
self.assertWarning(helperftn, w, expected)


def test_softspace(self):
expected = 'file.softspace not supported in 3.x'
Expand Down
6 changes: 5 additions & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4870,7 +4870,11 @@ cmp_outcome(int op, register PyObject *v, register PyObject *w)
CANNOT_CATCH_MSG, 1);
if (ret_val < 0)
return NULL;
}
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"Iterable exceptions are not supported in 3.x"
"access the arguments through the 'args' attribute instead", 1) < 0)
return NULL;
}
}
}
else {
Expand Down
8 changes: 8 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ PyDoc_STRVAR(excepthook_doc,
static PyObject *
sys_exc_info(PyObject *self, PyObject *noargs)
{
if (Py_Py3kWarningFlag) {
if (PyErr_WarnExplicit_WithFix(PyExc_Py3xWarning,
"sys.exc_info() not supported in 3.x",
"use except clauses", NULL, NULL,
NULL, NULL)) {
return NULL;
}
}
PyThreadState *tstate;
tstate = PyThreadState_GET();
return Py_BuildValue(
Expand Down