@@ -117,6 +117,13 @@ Type Objects
117
117
If no module is associated with the given type, sets :py:class: `TypeError `
118
118
and returns ``NULL ``.
119
119
120
+ This function is usually used to get the module in which a method is defined.
121
+ Note that in such a method, ``PyType_GetModule(Py_TYPE(self)) ``
122
+ may not return the intended result.
123
+ ``Py_TYPE(self) `` may be a *subclass * of the intended class, and subclasses
124
+ are not necessarily defined in the same module as their superclass.
125
+ See :c:type: `PyCMethod ` to get the class that defines the method.
126
+
120
127
.. versionadded :: 3.9
121
128
122
129
.. c :function :: void * PyType_GetModuleState (PyTypeObject *type)
@@ -151,9 +158,12 @@ The following functions and structs are used to create
151
158
If *bases* is ``NULL``, the *Py_tp_base* slot is used instead.
152
159
If that also is ``NULL``, the new type derives from :class:`object`.
153
160
154
- The *module* must be a module object or ``NULL``.
161
+ The *module* argument can be used to record the module in which the new
162
+ class is defined. It must be a module object or ``NULL``.
155
163
If not ``NULL``, the module is associated with the new type and can later be
156
164
retreived with :c:func:`PyType_GetModule`.
165
+ The associated module is not inherited by subclasses; it must be specified
166
+ for each class individually.
157
167
158
168
This function calls :c:func: `PyType_Ready ` on the new type.
159
169
0 commit comments