Skip to content

Commit 6412d30

Browse files
[3.15] Docs: Fix built-in function __self__ attribute descriptions (GH-159653) (GH-159710)
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 7d95f0d commit 6412d30

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
@@ -319,6 +319,8 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
319319
+-----------------+-------------------+---------------------------+
320320
| | __self__ | instance to which a |
321321
| | | method is bound, or |
322+
| | | module object a function |
323+
| | | was defined in, or |
322324
| | | ``None`` |
323325
+-----------------+-------------------+---------------------------+
324326

‎Doc/reference/datamodel.rst‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,8 @@ determined by the C function. Special read-only attributes:
863863
* :attr:`!__doc__` is the function's documentation string, or ``None`` if
864864
unavailable. See :attr:`function.__doc__`.
865865
* :attr:`!__name__` is the function's name. See :attr:`function.__name__`.
866-
* :attr:`!__self__` is set to ``None`` (but see the next item).
866+
* :attr:`!__self__` is the module object the function was defined in or
867+
``None`` if unavailable.
867868
* :attr:`!__module__` is the name of
868869
the module the function was defined in or ``None`` if unavailable.
869870
See :attr:`function.__module__`.

‎Lib/inspect.py‎

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

447448
def ismethodwrapper(object):

0 commit comments

Comments
 (0)