@@ -133,16 +133,36 @@ Tuple Objects
133133
134134.. c:function:: int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)
135135
136- Can be used to resize a tuple. *newsize * will be the new length of the tuple.
137- Because tuples are *supposed * to be immutable, this should only be used if there
138- is only one reference to the object. Do *not * use this if the tuple may already
139- be known to some other part of the code. The tuple will always grow or shrink
140- at the end. Think of this as destroying the old tuple and creating a new one,
141- only more efficiently. Returns ``0 `` on success. Client code should never
142- assume that the resulting value of ``*p `` will be the same as before calling
143- this function. If the object referenced by ``*p `` is replaced, the original
144- ``*p `` is destroyed. On failure, returns ``-1 `` and sets ``*p `` to ``NULL ``, and
145- raises :exc: `MemoryError ` or :exc: `SystemError `.
136+ Resize a tuple.
137+ *newsize * will be the new length of the tuple.
138+
139+ Because tuples are *supposed * to be immutable, this should only be used if
140+ there is only one reference to the object.
141+ Do *not * use this if the tuple may already be known to some other part of
142+ the code.
143+ The tuple hash value must not be computed yet.
144+
145+ The tuple will always grow or shrink at the end.
146+ Think of this as destroying the old tuple and creating a new one, only more
147+ efficiently.
148+
149+ Returns ``0 `` on success.
150+ Client code should never assume that the resulting value of ``*p `` will be
151+ the same as before calling this function.
152+ If the object referenced by ``*p `` is replaced, the original ``*p `` is
153+ destroyed.
154+
155+ On failure, returns ``-1 `` and sets ``*p `` to ``NULL ``, and raises
156+ :exc: `MemoryError ` or :exc: `SystemError `.
157+
158+ While tuple objects are usually immutable in Python, this special C API
159+ allows mutating a tuple object in-place.
160+ The returned tuple object can still be mutated using
161+ :c:func: `PyTuple_SetItem `; except if *newsize * is zero in which case it
162+ returns the immutable empty tuple.
163+
164+ .. versionchanged :: next
165+ The function now fails if the tuple hash value was already computed.
146166
147167
148168.. _struct-sequence-objects :
0 commit comments