Skip to content

Commit 8e62b08

Browse files
[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 415ebff) Co-authored-by: crypt0lith <118923461+crypt0lith@users.noreply.github.com>
1 parent 9770db8 commit 8e62b08

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎Doc/library/inspect.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
307307
+-----------------+-------------------+---------------------------+
308308
| | __self__ | instance to which a |
309309
| | | method is bound, or |
310+
| | | module object a function |
311+
| | | was defined in, or |
310312
| | | ``None`` |
311313
+-----------------+-------------------+---------------------------+
312314

‎Doc/reference/datamodel.rst‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ determined by the C function. Special read-only attributes:
849849
* :attr:`!__doc__` is the function's documentation string, or ``None`` if
850850
unavailable. See :attr:`function.__doc__`.
851851
* :attr:`!__name__` is the function's name. See :attr:`function.__name__`.
852-
* :attr:`!__self__` is set to ``None`` (but see the next item).
852+
* :attr:`!__self__` is the module object the function was defined in or
853+
``None`` if unavailable.
853854
* :attr:`!__module__` is the name of
854855
the module the function was defined in or ``None`` if unavailable.
855856
See :attr:`function.__module__`.

‎Lib/inspect.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ def isbuiltin(object):
442442
Built-in functions and methods provide these attributes:
443443
__doc__ documentation string
444444
__name__ original name of this function or method
445-
__self__ instance to which a method is bound, or None"""
445+
__self__ instance to which a method is bound, or module object
446+
a function was defined in, or None"""
446447
return isinstance(object, types.BuiltinFunctionType)
447448

448449
def ismethodwrapper(object):

0 commit comments

Comments
 (0)