summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-09-04 22:32:28 (GMT)
committerGitHub <noreply@github.com>2020-09-04 22:32:28 (GMT)
commitfbb9ee0a903fb9b7b4b807f85aed1de754da09e6 (patch)
tree86d5e0fb40da451c330abe4d39fa9ca97d3f4b3c /Doc
parentbf8bf1c0dc70f17bafd16fe4b22f777d6abd0750 (diff)
downloadcpython-fbb9ee0a903fb9b7b4b807f85aed1de754da09e6.zip
cpython-fbb9ee0a903fb9b7b4b807f85aed1de754da09e6.tar.gz
cpython-fbb9ee0a903fb9b7b4b807f85aed1de754da09e6.tar.bz2
[3.9] bpo-38787: Clarify docs for PyType_GetModule and warn against common mistake (GH-20215) (GH-21984)
(cherry picked from commit d9a966ae08258da2ce2a432c943d8194760f09c4) Co-authored-by: Petr Viktorin <encukou@gmail.com> Automerge-Triggered-By: @Mariatta
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/type.rst12
1 files changed, 11 insertions, 1 deletions
diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst
index 030304d..73f2687 100644
--- a/Doc/c-api/type.rst
+++ b/Doc/c-api/type.rst
@@ -117,6 +117,13 @@ Type Objects
If no module is associated with the given type, sets :py:class:`TypeError`
and returns ``NULL``.
+ This function is usually used to get the module in which a method is defined.
+ Note that in such a method, ``PyType_GetModule(Py_TYPE(self))``
+ may not return the intended result.
+ ``Py_TYPE(self)`` may be a *subclass* of the intended class, and subclasses
+ are not necessarily defined in the same module as their superclass.
+ See :c:type:`PyCMethod` to get the class that defines the method.
+
.. versionadded:: 3.9
.. c:function:: void* PyType_GetModuleState(PyTypeObject *type)
@@ -151,9 +158,12 @@ The following functions and structs are used to create
If *bases* is ``NULL``, the *Py_tp_base* slot is used instead.
If that also is ``NULL``, the new type derives from :class:`object`.
- The *module* must be a module object or ``NULL``.
+ The *module* argument can be used to record the module in which the new
+ class is defined. It must be a module object or ``NULL``.
If not ``NULL``, the module is associated with the new type and can later be
retreived with :c:func:`PyType_GetModule`.
+ The associated module is not inherited by subclasses; it must be specified
+ for each class individually.
This function calls :c:func:`PyType_Ready` on the new type.