@@ -142,6 +142,83 @@ 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 :: int PyTupleWriter_Init (PyTupleWriter *writer, Py_ssize_t size)
171+
172+ Initialize 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 success, return ``0 ``.
178+ On error, set an exception and return ``-1 ``.
179+
180+ *size * must be positive or zero.
181+
182+
183+ .. c :function :: PyObject* PyTupleWriter_Finish (PyTupleWriter *writer)
184+
185+ Finish a :c:type: `PyTupleWriter ` created by
186+ :c:func: `PyTupleWriter_Init `.
187+
188+ On success, return a Python :class: `tuple ` object.
189+ On error, set an exception and return ``NULL ``.
190+
191+ The writer instance is invalid after the call in any case.
192+ No API can be called on the writer after :c:func: `PyTupleWriter_Finish `.
193+
194+ .. c :function :: void PyTupleWriter_Discard (PyTupleWriter *writer)
195+
196+ Discard a :c:type: `PyTupleWriter ` created by :c:func: `PyTupleWriter_Init `.
197+
198+ Do nothing if *writer * is ``NULL ``.
199+
200+ The writer instance is invalid after the call.
201+ No API can be called on the writer after :c:func: `PyTupleWriter_Discard `.
202+
203+ .. c :function :: int PyTupleWriter_Add (PyTupleWriter *writer, PyObject *item)
204+
205+ Add an item to *writer *.
206+
207+ * On success, return ``0 ``.
208+ * If *item * is ``NULL `` with an exception set, return ``-1 ``.
209+ * On error, set an exception and return ``-1 ``.
210+
211+ .. c :function :: int PyTupleWriter_AddSteal (PyTupleWriter *writer, PyObject *item)
212+
213+ Similar to :c:func: `PyTupleWriter_Add `, but take the ownership of *item *.
214+
215+ .. c :function :: int PyTupleWriter_AddArray (PyTupleWriter *writer, PyObject *const *array, Py_ssize_t size)
216+
217+ Add items from an array to *writer *.
218+
219+ On success, return ``0 ``.
220+ On error, set an exception and return ``-1 ``.
221+
145222
146223.. _struct-sequence-objects :
147224
0 commit comments