Skip to content

Commit 8142416

Browse files
anujbharambeanuj-bharambe2004
authored andcommitted
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 3a1df78) Co-authored-by: Anuj Nitin Bharambe <119653366+anujbharambe@users.noreply.github.com> Co-authored-by: Anuj Bharambe <anujnitinb@gmail.com>
1 parent b274204 commit 8142416

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Doc/library/ast.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,25 @@ Root nodes
268268
Literals
269269
^^^^^^^^
270270

271-
.. class:: Constant(value)
271+
.. class:: Constant(value, kind)
272272

273273
A constant value. The ``value`` attribute of the ``Constant`` literal contains the
274274
Python object it represents. The values represented can be instances of :class:`str`,
275275
:class:`bytes`, :class:`int`, :class:`float`, :class:`complex`, and :class:`bool`,
276276
and the constants :data:`None` and :data:`Ellipsis`.
277277

278+
The ``kind`` attribute is an optional string. For string literals with a
279+
``u`` prefix, ``kind`` is set to ``'u'``. For all other
280+
constants, ``kind`` is ``None``.
281+
278282
.. doctest::
279283

280284
>>> print(ast.dump(ast.parse('123', mode='eval'), indent=4))
281285
Expression(
282286
body=Constant(value=123))
287+
>>> print(ast.dump(ast.parse("u'hello'", mode='eval'), indent=4))
288+
Expression(
289+
body=Constant(value='hello', kind='u'))
283290

284291

285292
.. class:: FormattedValue(value, conversion, format_spec)

0 commit comments

Comments
 (0)