From 81a15ea74e2607728fceb822dfcc1aabff00478a Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 12 Dec 2023 20:21:12 +0000 Subject: gh-101100: Further improve docs on function attributes (#113001) --- Doc/c-api/function.rst | 2 +- Doc/reference/datamodel.rst | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/function.rst b/Doc/c-api/function.rst index 75a05b4..e7fb509 100644 --- a/Doc/c-api/function.rst +++ b/Doc/c-api/function.rst @@ -35,7 +35,7 @@ There are a few functions specific to Python functions. must be a dictionary with the global variables accessible to the function. The function's docstring and name are retrieved from the code object. - :func:`~function.__module__` + :attr:`~function.__module__` is retrieved from *globals*. The argument defaults, annotations and closure are set to ``NULL``. :attr:`~function.__qualname__` is set to the same value as the code object's :attr:`~codeobject.co_qualname` field. diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index de79d72..16ee3e3 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -601,7 +601,7 @@ Most of these attributes check the type of the assigned value: or ``None`` if unavailable. * - .. attribute:: function.__defaults__ - - A :class:`tuple` containing default parameter values + - A :class:`tuple` containing default :term:`parameter` values for those parameters that have defaults, or ``None`` if no parameters have a default value. @@ -614,19 +614,22 @@ Most of these attributes check the type of the assigned value: See also: :attr:`__dict__ attributes `. * - .. attribute:: function.__annotations__ - - A :class:`dictionary ` containing annotations of parameters. + - A :class:`dictionary ` containing annotations of + :term:`parameters `. The keys of the dictionary are the parameter names, and ``'return'`` for the return annotation, if provided. See also: :ref:`annotations-howto`. * - .. attribute:: function.__kwdefaults__ - A :class:`dictionary ` containing defaults for keyword-only - parameters. + :term:`parameters `. * - .. attribute:: function.__type_params__ - A :class:`tuple` containing the :ref:`type parameters ` of a :ref:`generic function `. + .. versionadded:: 3.12 + Function objects also support getting and setting arbitrary attributes, which can be used, for example, to attach metadata to functions. Regular attribute dot-notation is used to get and set such attributes. -- cgit v0.12