From d43b6c9250b055ac1a2ce8706a4a9ae5a19d1603 Mon Sep 17 00:00:00 2001 From: Anuj Bharambe Date: Sat, 2 May 2026 11:21:29 +0530 Subject: [PATCH 1/2] gh-149267: Document ast.Constant.kind attribute The kind attribute of ast.Constant was not mentioned in the documentation. It is set to 'u' for u-prefixed string literals and None for all other constants. --- Doc/library/ast.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index 3c6e8745474316..9d0bbb74c2cd32 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -271,18 +271,25 @@ Root nodes Literals ^^^^^^^^ -.. class:: Constant(value) +.. class:: Constant(value, kind) A constant value. The ``value`` attribute of the ``Constant`` literal contains the 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`. + The ``kind`` attribute is an optional string. For string literals with a + ``u`` prefix (e.g. ``u'hello'``), ``kind`` is set to ``'u'``. For all other + constants, ``kind`` is ``None``. + .. doctest:: >>> print(ast.dump(ast.parse('123', mode='eval'), indent=4)) Expression( body=Constant(value=123)) + >>> print(ast.dump(ast.parse("u'hello'", mode='eval'), indent=4)) + Expression( + body=Constant(value='hello', kind='u')) .. class:: FormattedValue(value, conversion, format_spec) From db06995d4a4ff51bc777fcd41a284dcb7dcfd502 Mon Sep 17 00:00:00 2001 From: Anuj Bharambe Date: Sat, 2 May 2026 14:53:17 +0530 Subject: [PATCH 2/2] Address review: remove Latin abbreviation per style guide --- Doc/library/ast.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index 9d0bbb74c2cd32..cf394bb259af64 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -279,7 +279,7 @@ Literals and the constants :data:`None` and :data:`Ellipsis`. The ``kind`` attribute is an optional string. For string literals with a - ``u`` prefix (e.g. ``u'hello'``), ``kind`` is set to ``'u'``. For all other + ``u`` prefix, ``kind`` is set to ``'u'``. For all other constants, ``kind`` is ``None``. .. doctest::