Skip to content

Commit 39de3f8

Browse files
[3.13] pythongh-141004: Document PyType_SUPPORTS_WEAKREFS (pythonGH-141408) (pythonGH-141487)
* pythongh-141004: Document `PyType_SUPPORTS_WEAKREFS` (pythonGH-141408) Co-authored-by: Stan Ulbrych <[email protected]> (cherry picked from commit 9cd5427)
1 parent f127ff7 commit 39de3f8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Doc/c-api/type.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ Type Objects
181181
Python's default memory allocation mechanism to allocate a new instance and
182182
initialize all its contents to ``NULL``.
183183
184+
184185
.. c:function:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
185186
186187
Generic handler for the :c:member:`~PyTypeObject.tp_new` slot of a type object. Create a
187188
new instance using the type's :c:member:`~PyTypeObject.tp_alloc` slot.
188189
190+
189191
.. c:function:: int PyType_Ready(PyTypeObject *type)
190192
191193
Finalize a type object. This should be called on all type objects to finish
@@ -202,13 +204,15 @@ Type Objects
202204
GC protocol itself by at least implementing the
203205
:c:member:`~PyTypeObject.tp_traverse` handle.
204206
207+
205208
.. c:function:: PyObject* PyType_GetName(PyTypeObject *type)
206209
207210
Return the type's name. Equivalent to getting the type's
208211
:attr:`~type.__name__` attribute.
209212
210213
.. versionadded:: 3.11
211214
215+
212216
.. c:function:: PyObject* PyType_GetQualName(PyTypeObject *type)
213217
214218
Return the type's qualified name. Equivalent to getting the
@@ -224,13 +228,15 @@ Type Objects
224228
225229
.. versionadded:: 3.13
226230
231+
227232
.. c:function:: PyObject* PyType_GetModuleName(PyTypeObject *type)
228233
229234
Return the type's module name. Equivalent to getting the
230235
:attr:`type.__module__` attribute.
231236
232237
.. versionadded:: 3.13
233238
239+
234240
.. c:function:: void* PyType_GetSlot(PyTypeObject *type, int slot)
235241
236242
Return the function pointer stored in the given slot. If the
@@ -247,6 +253,7 @@ Type Objects
247253
:c:func:`PyType_GetSlot` can now accept all types.
248254
Previously, it was limited to :ref:`heap types <heap-types>`.
249255
256+
250257
.. c:function:: PyObject* PyType_GetModule(PyTypeObject *type)
251258
252259
Return the module object associated with the given type when the type was
@@ -266,6 +273,7 @@ Type Objects
266273
267274
.. versionadded:: 3.9
268275
276+
269277
.. c:function:: void* PyType_GetModuleState(PyTypeObject *type)
270278
271279
Return the state of the module object associated with the given type.
@@ -280,6 +288,7 @@ Type Objects
280288
281289
.. versionadded:: 3.9
282290
291+
283292
.. c:function:: PyObject* PyType_GetModuleByDef(PyTypeObject *type, struct PyModuleDef *def)
284293
285294
Find the first superclass whose module was created from
@@ -299,6 +308,7 @@ Type Objects
299308
300309
.. versionadded:: 3.11
301310
311+
302312
.. c:function:: int PyUnstable_Type_AssignVersionTag(PyTypeObject *type)
303313
304314
Attempt to assign a version tag to the given type.
@@ -309,6 +319,16 @@ Type Objects
309319
.. versionadded:: 3.12
310320
311321
322+
.. c:function:: int PyType_SUPPORTS_WEAKREFS(PyTypeObject *type)
323+
324+
Return true if instances of *type* support creating weak references, false
325+
otherwise. This function always succeeds. *type* must not be ``NULL``.
326+
327+
.. seealso::
328+
* :ref:`weakrefobjects`
329+
* :py:mod:`weakref`
330+
331+
312332
Creating Heap-Allocated Types
313333
.............................
314334
@@ -361,6 +381,7 @@ The following functions and structs are used to create
361381
362382
.. versionadded:: 3.12
363383
384+
364385
.. c:function:: PyObject* PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
365386
366387
Equivalent to ``PyType_FromMetaclass(NULL, module, spec, bases)``.
@@ -383,6 +404,7 @@ The following functions and structs are used to create
383404
:c:member:`~PyTypeObject.tp_new` is deprecated and in Python 3.14+ it
384405
will be no longer allowed.
385406
407+
386408
.. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
387409
388410
Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, bases)``.
@@ -400,6 +422,7 @@ The following functions and structs are used to create
400422
:c:member:`~PyTypeObject.tp_new` is deprecated and in Python 3.14+ it
401423
will be no longer allowed.
402424
425+
403426
.. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec)
404427
405428
Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, NULL)``.

Doc/c-api/weakref.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ as much as it can.
4545
weakly referenceable object, or if *callback* is not callable, ``None``, or
4646
``NULL``, this will return ``NULL`` and raise :exc:`TypeError`.
4747
48+
.. seealso::
49+
:c:func:`PyType_SUPPORTS_WEAKREFS` for checking if *ob* is weakly
50+
referenceable.
51+
4852
4953
.. c:function:: PyObject* PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
5054
@@ -57,6 +61,10 @@ as much as it can.
5761
is not a weakly referenceable object, or if *callback* is not callable,
5862
``None``, or ``NULL``, this will return ``NULL`` and raise :exc:`TypeError`.
5963
64+
.. seealso::
65+
:c:func:`PyType_SUPPORTS_WEAKREFS` for checking if *ob* is weakly
66+
referenceable.
67+
6068
6169
.. c:function:: int PyWeakref_GetRef(PyObject *ref, PyObject **pobj)
6270

0 commit comments

Comments
 (0)