@@ -103,20 +103,15 @@ Node classes
103103 For example, to create and populate an :class: `ast.UnaryOp ` node, you could
104104 use ::
105105
106- node = ast.UnaryOp()
107- node.op = ast.USub()
108- node.operand = ast.Constant()
109- node.operand.value = 5
110- node.operand.lineno = 0
111- node.operand.col_offset = 0
112- node.lineno = 0
113- node.col_offset = 0
114-
115- or the more compact ::
116-
117106 node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0),
118107 lineno=0, col_offset=0)
119108
109+ If a field that is optional in the grammar is omitted from the constructor,
110+ it defaults to ``None ``. If a list field is omitted, it defaults to the empty
111+ list. If any other field is omitted, a :exc: `DeprecationWarning ` is raised
112+ and the AST node will not have this field. In Python 3.15, this condition will
113+ raise an error.
114+
120115.. versionchanged :: 3.8
121116
122117 Class :class: `ast.Constant ` is now used for all constants.
@@ -140,6 +135,14 @@ Node classes
140135 In the meantime, instantiating them will return an instance of
141136 a different class.
142137
138+ .. deprecated-removed :: 3.13 3.15
139+
140+ Previous versions of Python allowed the creation of AST nodes that were missing
141+ required fields. Similarly, AST node constructors allowed arbitrary keyword
142+ arguments that were set as attributes of the AST node, even if they did not
143+ match any of the fields of the AST node. This behavior is deprecated and will
144+ be removed in Python 3.15.
145+
143146.. note ::
144147 The descriptions of the specific node classes displayed here
145148 were initially adapted from the fantastic `Green Tree
0 commit comments