Skip to content
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

gh-111666: Speed up BaseExceptionGroup.{derive,split,subgroup} #111667

Merged
merged 1 commit into from
Nov 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Speed up :meth:`BaseExceptionGroup.derive`,
:meth:`BaseExceptionGroup.subgroup`, and :meth:`BaseExceptionGroup.split` by
changing how they parse passed arguments.
26 changes: 6 additions & 20 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,13 +876,9 @@ BaseExceptionGroup_str(PyBaseExceptionGroupObject *self)
}

static PyObject *
BaseExceptionGroup_derive(PyObject *self_, PyObject *args)
BaseExceptionGroup_derive(PyObject *self_, PyObject *excs)
{
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroupObject_cast(self_);
PyObject *excs = NULL;
if (!PyArg_ParseTuple(args, "O", &excs)) {
return NULL;
}
PyObject *init_args = PyTuple_Pack(2, self->msg, excs);
if (!init_args) {
return NULL;
Expand Down Expand Up @@ -1176,13 +1172,8 @@ exceptiongroup_split_recursive(PyObject *exc,
}

static PyObject *
BaseExceptionGroup_split(PyObject *self, PyObject *args)
BaseExceptionGroup_split(PyObject *self, PyObject *matcher_value)
{
PyObject *matcher_value = NULL;
if (!PyArg_UnpackTuple(args, "split", 1, 1, &matcher_value)) {
return NULL;
}

_exceptiongroup_split_matcher_type matcher_type;
if (get_matcher_type(matcher_value, &matcher_type) < 0) {
return NULL;
Expand All @@ -1207,13 +1198,8 @@ BaseExceptionGroup_split(PyObject *self, PyObject *args)
}

static PyObject *
BaseExceptionGroup_subgroup(PyObject *self, PyObject *args)
BaseExceptionGroup_subgroup(PyObject *self, PyObject *matcher_value)
{
PyObject *matcher_value = NULL;
if (!PyArg_UnpackTuple(args, "subgroup", 1, 1, &matcher_value)) {
return NULL;
}

_exceptiongroup_split_matcher_type matcher_type;
if (get_matcher_type(matcher_value, &matcher_type) < 0) {
return NULL;
Expand Down Expand Up @@ -1488,9 +1474,9 @@ static PyMemberDef BaseExceptionGroup_members[] = {
static PyMethodDef BaseExceptionGroup_methods[] = {
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"derive", (PyCFunction)BaseExceptionGroup_derive, METH_VARARGS},
{"split", (PyCFunction)BaseExceptionGroup_split, METH_VARARGS},
{"subgroup", (PyCFunction)BaseExceptionGroup_subgroup, METH_VARARGS},
{"derive", (PyCFunction)BaseExceptionGroup_derive, METH_O},
{"split", (PyCFunction)BaseExceptionGroup_split, METH_O},
{"subgroup", (PyCFunction)BaseExceptionGroup_subgroup, METH_O},
{NULL}
};

Expand Down