@@ -42,7 +42,7 @@ Node classes
4242
4343.. class :: AST
4444
45- This is the base of all AST node classes. The actual node classes are
45+ This is the abstract base of all AST node classes. The actual node classes are
4646 derived from the :file: `Parser/Python.asdl ` file, which is reproduced
4747 :ref: `above <abstract-grammar >`. They are defined in the :mod: `!_ast ` C
4848 module and re-exported in :mod: `!ast `.
@@ -168,6 +168,15 @@ Node classes
168168 arguments that were set as attributes of the AST node, even if they did not
169169 match any of the fields of the AST node. These cases now raise a :exc: `TypeError `.
170170
171+ .. deprecated-removed :: next 3.20
172+
173+ In the :ref: `grammar above <abstract-grammar >`, the AST node classes that
174+ correspond to production rules with variants (aka "sums") are abstract
175+ classes. Previous versions of Python allowed for the creation of direct
176+ instances of these abstract node classes. This behavior is deprecated and
177+ will be removed in Python 3.20.
178+
179+
171180.. note ::
172181 The descriptions of the specific node classes displayed here
173182 were initially adapted from the fantastic `Green Tree
@@ -271,18 +280,25 @@ Root nodes
271280Literals
272281^^^^^^^^
273282
274- .. class :: Constant(value)
283+ .. class :: Constant(value, kind )
275284
276285 A constant value. The ``value `` attribute of the ``Constant `` literal contains the
277286 Python object it represents. The values represented can be instances of :class: `str `,
278287 :class: `bytes `, :class: `int `, :class: `float `, :class: `complex `, and :class: `bool `,
279288 and the constants :data: `None ` and :data: `Ellipsis `.
280289
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+
281294 .. doctest ::
282295
283296 >>> print (ast.dump(ast.parse(' 123' , mode = ' eval' ), indent = 4 ))
284297 Expression(
285298 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'))
286302
287303
288304.. class :: FormattedValue(value, conversion, format_spec)
@@ -2536,6 +2552,20 @@ and classes for traversing abstract syntax trees:
25362552 Added the *color * parameter.
25372553
25382554
2555+ .. function :: compare(a, b, /, *, compare_attributes=False)
2556+
2557+ Recursively compares two ASTs.
2558+
2559+ *compare_attributes * affects whether AST attributes are considered
2560+ in the comparison. If *compare_attributes * is ``False `` (default), then
2561+ attributes are ignored. Otherwise they must all be equal. This
2562+ option is useful to check whether the ASTs are structurally equal but
2563+ differ in whitespace or similar details. Attributes include line numbers
2564+ and column offsets.
2565+
2566+ .. versionadded :: 3.14
2567+
2568+
25392569.. _ast-compiler-flags :
25402570
25412571Compiler flags
@@ -2571,20 +2601,6 @@ effects on the compilation of a program:
25712601 .. versionadded :: 3.8
25722602
25732603
2574- .. function :: compare(a, b, /, *, compare_attributes=False)
2575-
2576- Recursively compares two ASTs.
2577-
2578- *compare_attributes * affects whether AST attributes are considered
2579- in the comparison. If *compare_attributes * is ``False `` (default), then
2580- attributes are ignored. Otherwise they must all be equal. This
2581- option is useful to check whether the ASTs are structurally equal but
2582- differ in whitespace or similar details. Attributes include line numbers
2583- and column offsets.
2584-
2585- .. versionadded :: 3.14
2586-
2587-
25882604.. _ast-cli :
25892605
25902606Command-line usage
0 commit comments