From 874fc1c136656b960817f1b89f60ff6ccee3c17b Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 20 Nov 2025 23:49:12 +0530 Subject: [PATCH 1/3] gh-141004: Document descriptor and dict proxy type objects --- Doc/c-api/descriptor.rst | 38 ++++++++++++++++++++++++++++++++++++++ Doc/c-api/dict.rst | 9 +++++++++ 2 files changed, 47 insertions(+) diff --git a/Doc/c-api/descriptor.rst b/Doc/c-api/descriptor.rst index 22c3b790cc3ec3..3bdb7383059658 100644 --- a/Doc/c-api/descriptor.rst +++ b/Doc/c-api/descriptor.rst @@ -21,12 +21,35 @@ found in the dictionary of type objects. .. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth) +.. c:var:: PyTypeObject PyMemberDescr_Type + + The type object for member descriptor objects created from + :c:type:`PyMemberDef` structures. These descriptors expose fields of a + C struct as attributes on a type, and correspond to ``member_descriptor`` + objects in the Python layer. + + .. c:function:: PyObject* PyDescr_NewMethod(PyTypeObject *type, struct PyMethodDef *meth) +.. c:var:: PyTypeObject PyMethodDescr_Type + The type object for method descriptor objects created from + :c:type:`PyMethodDef` structures. These descriptors expose C functions as + methods on a type, and correspond to ``method_descriptor`` objects in the + Python layer. + + .. c:function:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped) +.. c:var:: PyTypeObject PyWrapperDescr_Type + The type object for wrapper descriptor objects created by + :c:func:`PyDescr_NewWrapper` and :c:func:`PyWrapper_New`. Wrapper + descriptors are used internally to expose special methods implemented + via wrapper structures, and appear in Python as ``wrapper_descriptor`` + objects. + + .. c:function:: PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method) @@ -55,6 +78,21 @@ Built-in descriptors :class:`classmethod` in the Python layer. +.. c:var:: PyTypeObject PyClassMethodDescr_Type + + The type object for C-level class method descriptor objects. + This is the type of the descriptors created for :func:`classmethod` defined in C + extension types, and is the same object as :class:`classmethod` in the + Python layer. + + +.. c:var:: PyTypeObject PyGetSetDescr_Type + The type object for get/set descriptor objects created from + :c:type:`PyGetSetDef` structures. These descriptors implement attributes + whose value is computed by C getter and setter functions, and are used + for many built-in type attributes. + + .. c:function:: PyObject *PyClassMethod_New(PyObject *callable) Create a new :class:`classmethod` object wrapping *callable*. diff --git a/Doc/c-api/dict.rst b/Doc/c-api/dict.rst index b7f201811aad6c..75a348daee03b4 100644 --- a/Doc/c-api/dict.rst +++ b/Doc/c-api/dict.rst @@ -43,6 +43,15 @@ Dictionary Objects prevent modification of the dictionary for non-dynamic class types. +.. c:var:: PyTypeObject PyDictProxy_Type + The type object for mapping proxy objects created by + :c:func:`PyDictProxy_New` and for the read-only ``__dict__`` attribute + of many built-in types. A :c:type:`PyDictProxy_Type` instance provides a + dynamic, read-only view of an underlying dictionary: changes to the + underlying dictionary are reflected in the proxy, but the proxy itself + does not support mutation operations. + + .. c:function:: void PyDict_Clear(PyObject *p) Empty an existing dictionary of all key-value pairs. From cae92459f79f16378041f4eca843c9e4d0e42424 Mon Sep 17 00:00:00 2001 From: Yash Date: Fri, 21 Nov 2025 00:15:32 +0530 Subject: [PATCH 2/3] Fixing git errors --- Doc/c-api/descriptor.rst | 3 +++ Doc/c-api/dict.rst | 1 + 2 files changed, 4 insertions(+) diff --git a/Doc/c-api/descriptor.rst b/Doc/c-api/descriptor.rst index 3bdb7383059658..ecb18cadb6eb93 100644 --- a/Doc/c-api/descriptor.rst +++ b/Doc/c-api/descriptor.rst @@ -33,6 +33,7 @@ found in the dictionary of type objects. .. c:var:: PyTypeObject PyMethodDescr_Type + The type object for method descriptor objects created from :c:type:`PyMethodDef` structures. These descriptors expose C functions as methods on a type, and correspond to ``method_descriptor`` objects in the @@ -43,6 +44,7 @@ found in the dictionary of type objects. .. c:var:: PyTypeObject PyWrapperDescr_Type + The type object for wrapper descriptor objects created by :c:func:`PyDescr_NewWrapper` and :c:func:`PyWrapper_New`. Wrapper descriptors are used internally to expose special methods implemented @@ -87,6 +89,7 @@ Built-in descriptors .. c:var:: PyTypeObject PyGetSetDescr_Type + The type object for get/set descriptor objects created from :c:type:`PyGetSetDef` structures. These descriptors implement attributes whose value is computed by C getter and setter functions, and are used diff --git a/Doc/c-api/dict.rst b/Doc/c-api/dict.rst index 75a348daee03b4..dd88fafb95d00f 100644 --- a/Doc/c-api/dict.rst +++ b/Doc/c-api/dict.rst @@ -44,6 +44,7 @@ Dictionary Objects .. c:var:: PyTypeObject PyDictProxy_Type + The type object for mapping proxy objects created by :c:func:`PyDictProxy_New` and for the read-only ``__dict__`` attribute of many built-in types. A :c:type:`PyDictProxy_Type` instance provides a From 69ad04df8f795c324d03e6b4169eb14214464574 Mon Sep 17 00:00:00 2001 From: Yash Date: Fri, 21 Nov 2025 00:27:45 +0530 Subject: [PATCH 3/3] Lint fixes --- Doc/c-api/descriptor.rst | 2 +- Doc/c-api/dict.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/descriptor.rst b/Doc/c-api/descriptor.rst index ecb18cadb6eb93..2c29eca2cc8aa7 100644 --- a/Doc/c-api/descriptor.rst +++ b/Doc/c-api/descriptor.rst @@ -89,7 +89,7 @@ Built-in descriptors .. c:var:: PyTypeObject PyGetSetDescr_Type - + The type object for get/set descriptor objects created from :c:type:`PyGetSetDef` structures. These descriptors implement attributes whose value is computed by C getter and setter functions, and are used diff --git a/Doc/c-api/dict.rst b/Doc/c-api/dict.rst index dd88fafb95d00f..50b42d76ce9509 100644 --- a/Doc/c-api/dict.rst +++ b/Doc/c-api/dict.rst @@ -44,7 +44,7 @@ Dictionary Objects .. c:var:: PyTypeObject PyDictProxy_Type - + The type object for mapping proxy objects created by :c:func:`PyDictProxy_New` and for the read-only ``__dict__`` attribute of many built-in types. A :c:type:`PyDictProxy_Type` instance provides a