From e9a1d23e7120760ae616895d13a34d51ee169528 Mon Sep 17 00:00:00 2001 From: MannXo Date: Fri, 17 Oct 2025 12:35:12 +0330 Subject: [PATCH 1/2] gh-140196: Document missing AST node constructor behavior changes in ast.rst for Python 3.13 --- Doc/library/ast.rst | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index ea3ec7d95dc45d..d1148dd77a4bce 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -118,12 +118,12 @@ Node classes node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0), lineno=0, col_offset=0) - If a field that is optional in the grammar is omitted from the constructor, - it defaults to ``None``. If a list field is omitted, it defaults to the empty - list. If a field of type :class:`!ast.expr_context` is omitted, it defaults to - :class:`Load() `. If any other field is omitted, a :exc:`DeprecationWarning` is raised - and the AST node will not have this field. In Python 3.15, this condition will - raise an error. + If a field that is optional in the grammar is omitted from the constructor, + it defaults to ``None``. If a list field is omitted, it defaults to the empty + list. If a field of type :class:`!ast.expr_context` is omitted, it defaults to + :class:`Load() `. If any other field is omitted, a :exc:`DeprecationWarning` is raised + and the AST node will not have this field. In Python 3.15, this condition will + raise an error. .. versionchanged:: 3.8 @@ -134,6 +134,14 @@ Node classes Simple indices are represented by their value, extended slices are represented as tuples. +.. versionchanged:: 3.13 + + AST node constructors were changed to provide sensible defaults for omitted + fields: optional fields now default to ``None``, list fields default to an + empty list, and fields of type :class:`ast.expr_context` default to + :class:`Load() `. Previously, omitted attributes would not exist on constructed + nodes (accessing them raised :exc:`AttributeError`). + .. versionchanged:: 3.14 The :meth:`~object.__repr__` output of :class:`~ast.AST` nodes includes From ece522f33fdeca6f29507d399d64e2504c73cc32 Mon Sep 17 00:00:00 2001 From: MannXo Date: Fri, 17 Oct 2025 12:46:13 +0330 Subject: [PATCH 2/2] Removed the redundant whitespace --- Doc/library/ast.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index d1148dd77a4bce..bd405821929aa4 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -118,12 +118,12 @@ Node classes node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0), lineno=0, col_offset=0) - If a field that is optional in the grammar is omitted from the constructor, - it defaults to ``None``. If a list field is omitted, it defaults to the empty - list. If a field of type :class:`!ast.expr_context` is omitted, it defaults to - :class:`Load() `. If any other field is omitted, a :exc:`DeprecationWarning` is raised - and the AST node will not have this field. In Python 3.15, this condition will - raise an error. + If a field that is optional in the grammar is omitted from the constructor, + it defaults to ``None``. If a list field is omitted, it defaults to the empty + list. If a field of type :class:`!ast.expr_context` is omitted, it defaults to + :class:`Load() `. If any other field is omitted, a :exc:`DeprecationWarning` is raised + and the AST node will not have this field. In Python 3.15, this condition will + raise an error. .. versionchanged:: 3.8