Skip to content

Commit 3a1df78

Browse files
pythongh-149267: Document ast.Constant.kind attribute (python#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. --------- Co-authored-by: Anuj Bharambe <anujnitinb@gmail.com>
1 parent 7b0244d commit 3a1df78

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
@@ -280,18 +280,25 @@ Root nodes
280280
Literals
281281
^^^^^^^^
282282

283-
.. class:: Constant(value)
283+
.. class:: Constant(value, kind)
284284

285285
A constant value. The ``value`` attribute of the ``Constant`` literal contains the
286286
Python object it represents. The values represented can be instances of :class:`str`,
287287
:class:`bytes`, :class:`int`, :class:`float`, :class:`complex`, and :class:`bool`,
288288
and the constants :data:`None` and :data:`Ellipsis`.
289289

290+
The ``kind`` attribute is an optional string. For string literals with a
291+
``u`` prefix, ``kind`` is set to ``'u'``. For all other
292+
constants, ``kind`` is ``None``.
293+
290294
.. doctest::
291295

292296
>>> print(ast.dump(ast.parse('123', mode='eval'), indent=4))
293297
Expression(
294298
body=Constant(value=123))
299+
>>> print(ast.dump(ast.parse("u'hello'", mode='eval'), indent=4))
300+
Expression(
301+
body=Constant(value='hello', kind='u'))
295302

296303

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

0 commit comments

Comments
 (0)