https://github.com/python/cpython/commit/d19de375a204c74ab5f3a28ec42335bae139033d
commit: d19de375a204c74ab5f3a28ec42335bae139033d
branch: main
author: Sergey Miryanov <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-03-11T21:08:18Z
summary:
GH-145247: Use _PyTuple_FromPair in Parser and Python (#145842)
Use _PyTuple_FromPair in Parser and Python
files:
M Parser/pegen_errors.c
M Python/Python-tokenize.c
M Python/_warnings.c
M Python/bltinmodule.c
M Python/compile.c
M Python/hamt.c
M Python/marshal.c
M Python/pylifecycle.c
diff --git a/Parser/pegen_errors.c b/Parser/pegen_errors.c
index 1c61524d60a1af..312699415efd9a 100644
--- a/Parser/pegen_errors.c
+++ b/Parser/pegen_errors.c
@@ -3,6 +3,7 @@
#include "pycore_pyerrors.h" // _PyErr_ProgramDecodedTextObject()
#include "pycore_runtime.h" // _Py_ID()
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include "lexer/state.h"
#include "lexer/lexer.h"
#include "pegen.h"
@@ -41,7 +42,7 @@ _PyPegen_raise_tokenizer_init_error(PyObject *filename)
goto error;
}
- tuple = PyTuple_Pack(2, errstr, tmp);
+ tuple = _PyTuple_FromPair(errstr, tmp);
Py_DECREF(tmp);
if (!tuple) {
goto error;
@@ -393,7 +394,7 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject
*errtype,
if (!tmp) {
goto error;
}
- value = PyTuple_Pack(2, errstr, tmp);
+ value = _PyTuple_FromPair(errstr, tmp);
Py_DECREF(tmp);
if (!value) {
goto error;
diff --git a/Python/Python-tokenize.c b/Python/Python-tokenize.c
index 152d61c686722e..c50ff1190686c2 100644
--- a/Python/Python-tokenize.c
+++ b/Python/Python-tokenize.c
@@ -1,6 +1,7 @@
#include "Python.h"
#include "errcode.h"
#include "internal/pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION
+#include "internal/pycore_tuple.h" // _PyTuple_FromPair
#include "../Parser/lexer/state.h"
#include "../Parser/lexer/lexer.h"
#include "../Parser/tokenizer/tokenizer.h"
@@ -164,7 +165,7 @@ _tokenizer_error(tokenizeriterobject *it)
goto exit;
}
- value = PyTuple_Pack(2, errstr, tmp);
+ value = _PyTuple_FromPair(errstr, tmp);
if (!value) {
result = -1;
goto exit;
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 0ea785772f03b9..6b6ac238935765 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -7,6 +7,7 @@
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_traceback.h" // _Py_DisplaySourceLine()
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
#include <stdbool.h>
@@ -634,7 +635,7 @@ update_registry(PyInterpreterState *interp, PyObject
*registry, PyObject *text,
if (add_zero)
altkey = PyTuple_Pack(3, text, category, _PyLong_GetZero());
else
- altkey = PyTuple_Pack(2, text, category);
+ altkey = _PyTuple_FromPair(text, category);
rc = already_warned(interp, registry, altkey, 1);
Py_XDECREF(altkey);
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index fc69f6372028a6..5680e8971576cd 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -3341,7 +3341,7 @@ zip_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
if (lz->strict) {
return PyTuple_Pack(3, Py_TYPE(lz), lz->ittuple, Py_True);
}
- return PyTuple_Pack(2, Py_TYPE(lz), lz->ittuple);
+ return _PyTuple_FromPair((PyObject *)Py_TYPE(lz), lz->ittuple);
}
static PyObject *
diff --git a/Python/compile.c b/Python/compile.c
index 96779a0a219a55..4cf178b06ae11d 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -23,6 +23,7 @@
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_setobject.h" // _PySet_NextEntry()
#include "pycore_stats.h"
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
#include "cpython/code.h"
@@ -1697,7 +1698,7 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename,
PyCompilerFlags *pflags,
return NULL;
}
/* Allocate a copy of the instruction sequence on the heap */
- res = PyTuple_Pack(2, _PyCompile_InstrSequence(c), metadata);
+ res = _PyTuple_FromPair((PyObject *)_PyCompile_InstrSequence(c), metadata);
finally:
Py_XDECREF(metadata);
diff --git a/Python/hamt.c b/Python/hamt.c
index 881290a0e60db8..e4719e71a5259a 100644
--- a/Python/hamt.c
+++ b/Python/hamt.c
@@ -4,6 +4,7 @@
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_long.h" // _PyLong_Format()
#include "pycore_object.h" // _PyObject_GC_TRACK()
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include <stddef.h> // offsetof()
@@ -2542,7 +2543,7 @@ PyTypeObject _PyHamtItems_Type = {
static PyObject *
hamt_iter_yield_items(PyObject *key, PyObject *val)
{
- return PyTuple_Pack(2, key, val);
+ return _PyTuple_FromPair(key, val);
}
PyObject *
diff --git a/Python/marshal.c b/Python/marshal.c
index 59db6456552c35..cc6a787ba75022 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -14,6 +14,7 @@
#include "pycore_object.h" // _PyObject_IsUniquelyReferenced
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_setobject.h" // _PySet_NextEntryRef()
+#include "pycore_tuple.h" // _PyTuple_FromPairSteal
#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal()
#include "marshal.h" // Py_MARSHAL_VERSION
@@ -629,9 +630,7 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
Py_DECREF(value);
break;
}
- PyObject *pair = PyTuple_Pack(2, dump, value);
- Py_DECREF(dump);
- Py_DECREF(value);
+ PyObject *pair = _PyTuple_FromPairSteal(dump, value);
if (pair == NULL) {
p->error = WFERR_NOMEMORY;
break;
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 21d1e036d31540..2b8e9a02cb6184 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -30,6 +30,7 @@
#include "pycore_stats.h" // _PyStats_InterpInit()
#include "pycore_sysmodule.h" // _PySys_ClearAttrString()
#include "pycore_traceback.h" // _Py_DumpTracebackThreads()
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_typeobject.h" // _PyTypes_InitTypes()
#include "pycore_typevarobject.h" // _Py_clear_generic_types()
#include "pycore_unicodeobject.h" // _PyUnicode_InitTypes()
@@ -1613,7 +1614,7 @@ finalize_remove_modules(PyObject *modules, int verbose)
if (weaklist != NULL) { \
PyObject *wr = PyWeakref_NewRef(mod, NULL); \
if (wr) { \
- PyObject *tup = PyTuple_Pack(2, name, wr); \
+ PyObject *tup = _PyTuple_FromPair(name, wr); \
if (!tup || PyList_Append(weaklist, tup) < 0) { \
PyErr_FormatUnraisable("Exception ignored while removing
modules"); \
} \
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]