mirror of
https://github.com/python/cpython.git
synced 2025-10-29 01:22:59 +00:00
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>
This commit is contained in:
parent
5a1559d949
commit
ed4dfd8825
10 changed files with 4675 additions and 49 deletions
|
|
@ -753,6 +753,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
|
|||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_check_retval_));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_dealloc_warn));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_feature_version));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_field_types));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_fields_));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_finalizing));
|
||||
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_find_and_load));
|
||||
|
|
|
|||
|
|
@ -242,6 +242,7 @@ struct _Py_global_strings {
|
|||
STRUCT_FOR_ID(_check_retval_)
|
||||
STRUCT_FOR_ID(_dealloc_warn)
|
||||
STRUCT_FOR_ID(_feature_version)
|
||||
STRUCT_FOR_ID(_field_types)
|
||||
STRUCT_FOR_ID(_fields_)
|
||||
STRUCT_FOR_ID(_finalizing)
|
||||
STRUCT_FOR_ID(_find_and_load)
|
||||
|
|
|
|||
1
Include/internal/pycore_runtime_init_generated.h
generated
1
Include/internal/pycore_runtime_init_generated.h
generated
|
|
@ -751,6 +751,7 @@ extern "C" {
|
|||
INIT_ID(_check_retval_), \
|
||||
INIT_ID(_dealloc_warn), \
|
||||
INIT_ID(_feature_version), \
|
||||
INIT_ID(_field_types), \
|
||||
INIT_ID(_fields_), \
|
||||
INIT_ID(_finalizing), \
|
||||
INIT_ID(_find_and_load), \
|
||||
|
|
|
|||
|
|
@ -567,6 +567,9 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) {
|
|||
string = &_Py_ID(_feature_version);
|
||||
assert(_PyUnicode_CheckConsistency(string, 1));
|
||||
_PyUnicode_InternInPlace(interp, &string);
|
||||
string = &_Py_ID(_field_types);
|
||||
assert(_PyUnicode_CheckConsistency(string, 1));
|
||||
_PyUnicode_InternInPlace(interp, &string);
|
||||
string = &_Py_ID(_fields_);
|
||||
assert(_PyUnicode_CheckConsistency(string, 1));
|
||||
_PyUnicode_InternInPlace(interp, &string);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue