]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-105858: Improve AST node constructors (#105880)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Wed, 28 Feb 2024 02:13:03 +0000 (18:13 -0800)
committerGitHub <noreply@github.com>
Wed, 28 Feb 2024 02:13:03 +0000 (18:13 -0800)
commited4dfd8825b49e16a0fcb9e67baf1b58bb8d438f
tree88935b427cd68a5a249f0876f3a1cbe5ce241ce8
parent5a1559d9493dd298a08c4be32b52295aa3eb89e5
gh-105858: Improve AST node constructors (#105880)

Demonstration:

>>> ast.FunctionDef.__annotations__
{'name': <class 'str'>, 'args': <class 'ast.arguments'>, 'body': list[ast.stmt], 'decorator_list': list[ast.expr], 'returns': ast.expr | None, 'type_comment': str | None, 'type_params': list[ast.type_param]}
>>> ast.FunctionDef()
<stdin>:1: DeprecationWarning: FunctionDef.__init__ missing 1 required positional argument: 'name'. This will become an error in Python 3.15.
<stdin>:1: DeprecationWarning: FunctionDef.__init__ missing 1 required positional argument: 'args'. This will become an error in Python 3.15.
<ast.FunctionDef object at 0x101959460>
>>> node = ast.FunctionDef(name="foo", args=ast.arguments())
>>> node.decorator_list
[]
>>> ast.FunctionDef(whatever="you want", name="x", args=ast.arguments())
<stdin>:1: DeprecationWarning: FunctionDef.__init__ got an unexpected keyword argument 'whatever'. Support for arbitrary keyword arguments is deprecated and will be removed in Python 3.15.
<ast.FunctionDef object at 0x1019581f0>
Doc/library/ast.rst
Doc/whatsnew/3.13.rst
Include/internal/pycore_global_objects_fini_generated.h
Include/internal/pycore_global_strings.h
Include/internal/pycore_runtime_init_generated.h
Include/internal/pycore_unicodeobject_generated.h
Lib/test/test_ast.py
Misc/NEWS.d/next/Core and Builtins/2023-06-16-21-29-06.gh-issue-105858.Q7h0EV.rst [new file with mode: 0644]
Parser/asdl_c.py
Python/Python-ast.c