gh-117266: Fix crashes on user-created AST subclasses (GH-117276)

Fix crashes on user-created AST subclasses
This commit is contained in:
Jelle Zijlstra 2024-03-28 04:30:31 -06:00 committed by GitHub
parent 8cb7d7ff86
commit 4c71d51a4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 69 additions and 4 deletions

15
Python/Python-ast.c generated
View file

@ -5119,11 +5119,22 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
Py_ssize_t size = PySet_Size(remaining_fields);
PyObject *field_types = NULL, *remaining_list = NULL;
if (size > 0) {
if (!PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types),
&field_types)) {
if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types),
&field_types) < 0) {
res = -1;
goto cleanup;
}
if (field_types == NULL) {
if (PyErr_WarnFormat(
PyExc_DeprecationWarning, 1,
"%.400s provides _fields but not _field_types. "
"This will become an error in Python 3.15.",
Py_TYPE(self)->tp_name
) < 0) {
res = -1;
}
goto cleanup;
}
remaining_list = PySequence_List(remaining_fields);
if (!remaining_list) {
goto set_remaining_cleanup;