bpo-46431: improve error message on invalid calls to BaseExceptionGroup.__new__ (GH-30854)

This commit is contained in:
Irit Katriel 2022-01-24 21:47:40 +00:00 committed by GitHub
parent 1c705fda8f
commit 573b545157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 2 deletions

View File

@ -22,7 +22,7 @@ class TestExceptionGroupTypeHierarchy(unittest.TestCase):
class BadConstructorArgs(unittest.TestCase):
def test_bad_EG_construction__too_many_args(self):
MSG = 'function takes exactly 2 arguments'
MSG = 'BaseExceptionGroup.__new__\(\) takes exactly 2 arguments'
with self.assertRaisesRegex(TypeError, MSG):
ExceptionGroup('no errors')
with self.assertRaisesRegex(TypeError, MSG):

View File

@ -0,0 +1 @@
Improve error message on invalid calls to :meth:`BaseExceptionGroup.__new__`.

View File

@ -685,7 +685,10 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *message = NULL;
PyObject *exceptions = NULL;
if (!PyArg_ParseTuple(args, "UO", &message, &exceptions)) {
if (!PyArg_ParseTuple(args,
"UO:BaseExceptionGroup.__new__",
&message,
&exceptions)) {
return NULL;
}