Skip to content

Commit e9a1d23

Browse files
committed
gh-140196: Document missing AST node constructor behavior changes in ast.rst for Python 3.13
1 parent 9a87ce8 commit e9a1d23

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Doc/library/ast.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ Node classes
118118
node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0),
119119
lineno=0, col_offset=0)
120120

121-
If a field that is optional in the grammar is omitted from the constructor,
122-
it defaults to ``None``. If a list field is omitted, it defaults to the empty
123-
list. If a field of type :class:`!ast.expr_context` is omitted, it defaults to
124-
:class:`Load() <ast.Load>`. If any other field is omitted, a :exc:`DeprecationWarning` is raised
125-
and the AST node will not have this field. In Python 3.15, this condition will
126-
raise an error.
121+
If a field that is optional in the grammar is omitted from the constructor,
122+
it defaults to ``None``. If a list field is omitted, it defaults to the empty
123+
list. If a field of type :class:`!ast.expr_context` is omitted, it defaults to
124+
:class:`Load() <ast.Load>`. If any other field is omitted, a :exc:`DeprecationWarning` is raised
125+
and the AST node will not have this field. In Python 3.15, this condition will
126+
raise an error.
127127

128128
.. versionchanged:: 3.8
129129

@@ -134,6 +134,14 @@ Node classes
134134
Simple indices are represented by their value, extended slices are
135135
represented as tuples.
136136

137+
.. versionchanged:: 3.13
138+
139+
AST node constructors were changed to provide sensible defaults for omitted
140+
fields: optional fields now default to ``None``, list fields default to an
141+
empty list, and fields of type :class:`ast.expr_context` default to
142+
:class:`Load() <ast.Load>`. Previously, omitted attributes would not exist on constructed
143+
nodes (accessing them raised :exc:`AttributeError`).
144+
137145
.. versionchanged:: 3.14
138146

139147
The :meth:`~object.__repr__` output of :class:`~ast.AST` nodes includes

0 commit comments

Comments
 (0)