]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
ast docs: Fix description of ast.Constant (#134741)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Fri, 30 May 2025 04:11:20 +0000 (21:11 -0700)
committerGitHub <noreply@github.com>
Fri, 30 May 2025 04:11:20 +0000 (21:11 -0700)
Contrary to the current docs, ast.Constant will never hold containers
such as frozenset or tuple; the Python parser only emits it for simple
literals.

For precision, add the exact list of types that may be contained in an
ast.Constant.

Doc/library/ast.rst

index ca9a6b0712c9a283451b49d87826b78697077731..cf22250cac60916cbd40ddf0eeb28b5f52c1ce92 100644 (file)
@@ -268,9 +268,9 @@ Literals
 .. class:: Constant(value)
 
    A constant value. The ``value`` attribute of the ``Constant`` literal contains the
-   Python object it represents. The values represented can be simple types
-   such as a number, string or ``None``, but also immutable container types
-   (tuples and frozensets) if all of their elements are constant.
+   Python object it represents. The values represented can be instances of :class:`str`,
+   :class:`bytes`, :class:`int`, :class:`float`, :class:`complex`, and :class:`bool`,
+   and the constants :data:`None` and :data:`Ellipsis`.
 
    .. doctest::