https://github.com/python/cpython/commit/b4b2e0cd7c788ddc4ec3b5614ff17c9549df4c40 commit: b4b2e0cd7c788ddc4ec3b5614ff17c9549df4c40 branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: JelleZijlstra <[email protected]> date: 2026-05-03T16:04:14Z summary:
[3.14] gh-149267: Document ast.Constant.kind attribute (GH-149268) (#149293) 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 <[email protected]> Co-authored-by: Anuj Bharambe <[email protected]> files: M Doc/library/ast.rst diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index 583b55cc8c14b8..2fbc391f7e556c 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -274,18 +274,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) _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
