https://github.com/python/cpython/commit/8e62b0898a28cdbc0bd80a97dbfef6036b4d5bcf
commit: 8e62b0898a28cdbc0bd80a97dbfef6036b4d5bcf
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2026-10-19T19:20:33Z
summary:

[3.14] Docs: Fix built-in function `__self__` attribute descriptions 
(GH-159653) (GH-159711)

Since PEP 3121, functions in C modules are bound to their module, so
their __self__ is the module object. The inspect.isbuiltin docstring,
the inspect attribute table and the data model reference still say
it is None, as it was in Python 2. Describe it as the module object
the function was defined in, or None.
(cherry picked from commit 415ebffc47e8303d61cf97faf4ddb474334d736d)

Co-authored-by: crypt0lith <[email protected]>

files:
M Doc/library/inspect.rst
M Doc/reference/datamodel.rst
M Lib/inspect.py

diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index 718a1c3245df7b2..0d7cf4eb3566405 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -307,6 +307,8 @@ attributes (see :ref:`import-mod-attrs` for module 
attributes):
 +-----------------+-------------------+---------------------------+
 |                 | __self__          | instance to which a       |
 |                 |                   | method is bound, or       |
+|                 |                   | module object a function  |
+|                 |                   | was defined in, or        |
 |                 |                   | ``None``                  |
 +-----------------+-------------------+---------------------------+
 
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index fcc2dffb3928174..b800cd5931992ef 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -849,7 +849,8 @@ determined by the C function. Special read-only attributes:
 * :attr:`!__doc__` is the function's documentation string, or ``None`` if
   unavailable. See :attr:`function.__doc__`.
 * :attr:`!__name__` is the function's name. See :attr:`function.__name__`.
-* :attr:`!__self__` is set to ``None`` (but see the next item).
+* :attr:`!__self__` is the module object the function was defined in or
+  ``None`` if unavailable.
 * :attr:`!__module__` is the name of
   the module the function was defined in or ``None`` if unavailable.
   See :attr:`function.__module__`.
diff --git a/Lib/inspect.py b/Lib/inspect.py
index aae1b73ecc4a901..e3776c2c496cb17 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -442,7 +442,8 @@ def isbuiltin(object):
     Built-in functions and methods provide these attributes:
         __doc__         documentation string
         __name__        original name of this function or method
-        __self__        instance to which a method is bound, or None"""
+        __self__        instance to which a method is bound, or module object
+                        a function was defined in, or None"""
     return isinstance(object, types.BuiltinFunctionType)
 
 def ismethodwrapper(object):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to