From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sat, 2 May 2026 17:05:24 +0000 (+0200) Subject: [3.13] gh-149267: Document ast.Constant.kind attribute (GH-149268) (#149294) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e961c002555b55b0aed1c53e3756d9e0f1b8fcfa;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-149267: Document ast.Constant.kind attribute (GH-149268) (#149294) gh-149267: Document ast.Constant.kind attribute (GH-149268) 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. --------- (cherry picked from commit 3a1df787e1e630d3d57e99226604ddceb8c47229) Co-authored-by: Anuj Nitin Bharambe <119653366+anujbharambe@users.noreply.github.com> Co-authored-by: Anuj Bharambe --- diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index 42728b1394a3..3e1d9fde3fc6 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -268,18 +268,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, ``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)