ast docs: Fix description of ast.Constant (#134741)

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.
This commit is contained in:
Jelle Zijlstra 2025-05-29 21:11:20 -07:00 committed by GitHub
parent a4251411a9
commit 381020d41f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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