@@ -142,6 +142,82 @@ Tuple Objects
142142 ``*p `` is destroyed. On failure, returns ``-1 `` and sets ``*p `` to ``NULL ``, and
143143 raises :exc: `MemoryError ` or :exc: `SystemError `.
144144
145+ .. deprecated :: 3.15
146+ Use the :ref: `PyTupleWriter API <pytuplewriter >` instead.
147+
148+
149+ .. _pytuplewriter :
150+
151+ PyTupleWriter
152+ -------------
153+
154+ The :c:type: `PyTupleWriter ` API can be used to create a Python :class: `tuple `
155+ object.
156+
157+ .. versionadded :: next
158+
159+ .. c :type :: PyTupleWriter
160+
161+ A tuple writer instance.
162+
163+ The API is **not thread safe **: a writer should only be used by a single
164+ thread at the same time.
165+
166+ The instance must be destroyed by :c:func: `PyTupleWriter_Finish ` on
167+ success, or :c:func: `PyTupleWriter_Discard ` on error.
168+
169+
170+ .. c :function :: PyTupleWriter* PyTupleWriter_Create (Py_ssize_t size)
171+
172+ Create a :c:type:`PyTupleWriter` to add *size* items.
173+
174+ If *size* is greater than zero, preallocate *size* items. The caller is
175+ responsible to add *size* items using :c:func:`PyTupleWriter_Add`.
176+
177+ On error, set an exception and return ``NULL``.
178+
179+ *size* must be positive or zero.
180+
181+
182+ .. c:function:: PyObject* PyTupleWriter_Finish(PyTupleWriter *writer)
183+
184+ Finish a :c:type: `PyTupleWriter ` created by
185+ :c:func: `PyTupleWriter_Create `.
186+
187+ On success, return a Python :class: `tuple ` object.
188+ On error, set an exception and return ``NULL ``.
189+
190+ The writer instance is invalid after the call in any case.
191+ No API can be called on the writer after :c:func: `PyTupleWriter_Finish `.
192+
193+ .. c :function :: void PyTupleWriter_Discard (PyTupleWriter *writer)
194+
195+ Discard a :c:type: `PyTupleWriter ` created by :c:func: `PyTupleWriter_Create `.
196+
197+ Do nothing if *writer * is ``NULL ``.
198+
199+ The writer instance is invalid after the call.
200+ No API can be called on the writer after :c:func: `PyTupleWriter_Discard `.
201+
202+ .. c :function :: int PyTupleWriter_Add (PyTupleWriter *writer, PyObject *item)
203+
204+ Add an item to *writer *.
205+
206+ * On success, return ``0 ``.
207+ * If *item * is ``NULL `` with an exception set, return ``-1 ``.
208+ * On error, set an exception and return ``-1 ``.
209+
210+ .. c :function :: int PyTupleWriter_AddSteal (PyTupleWriter *writer, PyObject *item)
211+
212+ Similar to :c:func: `PyTupleWriter_Add `, but take the ownership of *item *.
213+
214+ .. c :function :: int PyTupleWriter_AddArray (PyTupleWriter *writer, PyObject *const *array, Py_ssize_t size)
215+
216+ Add items from an array to *writer *.
217+
218+ On success, return ``0 ``.
219+ On error, set an exception and return ``-1 ``.
220+
145221
146222.. _struct-sequence-objects :
147223
0 commit comments