Skip to content

Commit 57375b3

Browse files
andrewlouxclaude
andcommitted
gh-140009: Replace PyTuple_Pack with PyTuple_FromArray in _warnings
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b488f33 commit 57375b3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Python/_warnings.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ create_filter(PyObject *category, PyObject *action_str, const char *modname)
8888
}
8989

9090
/* This assumes the line number is zero for now. */
91-
PyObject *filter = PyTuple_Pack(5, action_str, Py_None,
92-
category, modname_obj, _PyLong_GetZero());
91+
PyObject *items[] = {action_str, Py_None, category, modname_obj,
92+
_PyLong_GetZero()};
93+
PyObject *filter = PyTuple_FromArray(items, 5);
9394
Py_DECREF(modname_obj);
9495
return filter;
9596
}
@@ -631,10 +632,14 @@ update_registry(PyInterpreterState *interp, PyObject *registry, PyObject *text,
631632
PyObject *altkey;
632633
int rc;
633634

634-
if (add_zero)
635-
altkey = PyTuple_Pack(3, text, category, _PyLong_GetZero());
636-
else
637-
altkey = PyTuple_Pack(2, text, category);
635+
if (add_zero) {
636+
PyObject *items[] = {text, category, _PyLong_GetZero()};
637+
altkey = PyTuple_FromArray(items, 3);
638+
}
639+
else {
640+
PyObject *items[] = {text, category};
641+
altkey = PyTuple_FromArray(items, 2);
642+
}
638643

639644
rc = already_warned(interp, registry, altkey, 1);
640645
Py_XDECREF(altkey);
@@ -815,7 +820,8 @@ warn_explicit(PyThreadState *tstate, PyObject *category, PyObject *message,
815820
}
816821

817822
/* Create key. */
818-
key = PyTuple_Pack(3, text, category, lineno_obj);
823+
PyObject *key_items[] = {text, category, lineno_obj};
824+
key = PyTuple_FromArray(key_items, 3);
819825
if (key == NULL)
820826
goto cleanup;
821827

0 commit comments

Comments
 (0)