]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-149267: Document ast.Constant.kind attribute (#149268)
authorAnuj Nitin Bharambe <119653366+anujbharambe@users.noreply.github.com>
Sat, 2 May 2026 16:55:29 +0000 (22:25 +0530)
committerGitHub <noreply@github.com>
Sat, 2 May 2026 16:55:29 +0000 (09:55 -0700)
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.

---------

Co-authored-by: Anuj Bharambe <anujnitinb@gmail.com>
Doc/library/ast.rst

index 49be47f15aa1a9c7a1b8972ee931c512afddbe91..e10b8e22df0fefbf367c3e648555c7b7e9c5f2a6 100644 (file)
@@ -280,18 +280,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)