diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2024-03-28 10:30:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-28 10:30:31 (GMT) |
commit | 4c71d51a4b7989fc8754ba512c40e21666f9db0d (patch) | |
tree | 698a1996cb489c6426a6353c033983435640c143 /Parser | |
parent | 8cb7d7ff86a1a2d41195f01ba4f218941dd7308c (diff) | |
download | cpython-4c71d51a4b7989fc8754ba512c40e21666f9db0d.zip cpython-4c71d51a4b7989fc8754ba512c40e21666f9db0d.tar.gz cpython-4c71d51a4b7989fc8754ba512c40e21666f9db0d.tar.bz2 |
gh-117266: Fix crashes on user-created AST subclasses (GH-117276)
Fix crashes on user-created AST subclasses
Diffstat (limited to 'Parser')
-rwxr-xr-x | Parser/asdl_c.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 59cc391..c4df2c5 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -973,11 +973,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; |