FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-102594: test_fetch_exception_with_broken_init @ 3.12.0a3 by rwgk · Pull Request #102606 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 10 additions & 0 deletions Lib/test/test_exceptions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,20 @@ def test_capi3():
self.assertRaises(SystemError, _testcapi.raise_exception,
InvalidException, 1)

def test_capi4():
import _testcapi
class FlakyException(Exception):
def __init__(self):
raise ValueError("Broken __init__")

fetched_type_name = _testcapi.exc_set_object_fetch(FlakyException, ())
self.assertEqual(fetched_type_name, 'FlakyException')

if not sys.platform.startswith('java'):
test_capi1()
test_capi2()
test_capi3()
test_capi4()

def test_WindowsError(self):
try:
Expand Down
30 changes: 30 additions & 0 deletions Modules/_testcapimodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,35 @@ pyobject_bytes_from_null(PyObject *self, PyObject *Py_UNUSED(ignored))
return PyObject_Bytes(NULL);
}

static PyObject *
exc_set_object_fetch(PyObject *self, PyObject *args)
{
PyObject *exc;
PyObject *obj;
PyObject *type;
PyObject *value;
PyObject *tb;

if (!PyArg_ParseTuple(args, "OO:exc_set_object", &exc, &obj)) {
return NULL;
}

PyErr_SetObject(exc, obj);
PyErr_Fetch(&type, &value, &tb);
Py_XDECREF(value);
Py_XDECREF(tb);
if (!PyType_Check(type)) {
Py_XDECREF(type);
PyErr_SetString(PyExc_RuntimeError,
"PyErr_Fetch() produced invalid type");
return NULL;
}
PyObject *fetched_type_name = PyUnicode_FromString(
((PyTypeObject *) type)->tp_name);
Py_XDECREF(type);
return fetched_type_name;
}

static PyObject *
raise_exception(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -3141,6 +3170,7 @@ function_set_kw_defaults(PyObject *self, PyObject *args)
static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *);

static PyMethodDef TestMethods[] = {
{"exc_set_object_fetch", exc_set_object_fetch, METH_VARARGS},
{"raise_exception", raise_exception, METH_VARARGS},
{"raise_memoryerror", raise_memoryerror, METH_NOARGS},
{"set_errno", set_errno, METH_VARARGS},
Expand Down

Back | FazBrowse Home | New Git URL