gh-101100: Improve documentation on function attributes (#112933)

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
Alex Waygood 2023-12-11 10:00:42 +00:00 committed by GitHub
parent 9cdf05bc28
commit 4c5b9c107a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 158 additions and 129 deletions

View file

@ -1225,9 +1225,10 @@ Classes and functions
* If ``obj`` is a class, ``globals`` defaults to
``sys.modules[obj.__module__].__dict__`` and ``locals`` defaults
to the ``obj`` class namespace.
* If ``obj`` is a callable, ``globals`` defaults to ``obj.__globals__``,
* If ``obj`` is a callable, ``globals`` defaults to
:attr:`obj.__globals__ <function.__globals__>`,
although if ``obj`` is a wrapped function (using
``functools.update_wrapper()``) it is first unwrapped.
:func:`functools.update_wrapper`) it is first unwrapped.
Calling ``get_annotations`` is best practice for accessing the
annotations dict of any object. See :ref:`annotations-howto` for

View file

@ -5384,10 +5384,10 @@ Code objects are used by the implementation to represent "pseudo-compiled"
executable Python code such as a function body. They differ from function
objects because they don't contain a reference to their global execution
environment. Code objects are returned by the built-in :func:`compile` function
and can be extracted from function objects through their :attr:`__code__`
attribute. See also the :mod:`code` module.
and can be extracted from function objects through their
:attr:`~function.__code__` attribute. See also the :mod:`code` module.
Accessing ``__code__`` raises an :ref:`auditing event <auditing>`
Accessing :attr:`~function.__code__` raises an :ref:`auditing event <auditing>`
``object.__getattr__`` with arguments ``obj`` and ``"__code__"``.
.. index::

View file

@ -84,12 +84,12 @@ alone XML-RPC servers.
Register a function that can respond to XML-RPC requests. If *name* is given,
it will be the method name associated with *function*, otherwise
``function.__name__`` will be used. *name* is a string, and may contain
:attr:`function.__name__` will be used. *name* is a string, and may contain
characters not legal in Python identifiers, including the period character.
This method can also be used as a decorator. When used as a decorator,
*name* can only be given as a keyword argument to register *function* under
*name*. If no *name* is given, ``function.__name__`` will be used.
*name*. If no *name* is given, :attr:`function.__name__` will be used.
.. versionchanged:: 3.7
:meth:`register_function` can be used as a decorator.
@ -298,12 +298,12 @@ requests sent to Python CGI scripts.
Register a function that can respond to XML-RPC requests. If *name* is given,
it will be the method name associated with *function*, otherwise
``function.__name__`` will be used. *name* is a string, and may contain
:attr:`function.__name__` will be used. *name* is a string, and may contain
characters not legal in Python identifiers, including the period character.
This method can also be used as a decorator. When used as a decorator,
*name* can only be given as a keyword argument to register *function* under
*name*. If no *name* is given, ``function.__name__`` will be used.
*name*. If no *name* is given, :attr:`function.__name__` will be used.
.. versionchanged:: 3.7
:meth:`register_function` can be used as a decorator.