8000 gh-105858: Improve AST node constructors by JelleZijlstra · Pull Request #105880 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105858: Improve AST node constructors #105880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix subclasses
  • Loading branch information
JelleZijlstra committed Jun 22, 2023
commit c74740a08446e5378547fb9810d3d1c830e2ab64
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,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)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,11 @@ def emit_annotations(self, name, fields):
self.emit("Py_DECREF(type);", 2)
self.emit_annotations_error(name, 2)
self.emit("}", 1)
self.emit(f'cond = PyObject_SetAttrString(state->{name}_type, "_field_types", {name}_annotations) == 0;', 1)
self.emit_annotations_error(name, 1)
self.emit(f'cond = PyObject_SetAttrString(state->{name}_type, "__annotations__", {name}_annotations) == 0;', 1)
self.emit_annotations_error(name, 1)
self.emit(f"Py_DECREF({name}_annotations);", 1)
self.emit("if (!cond) return 0;", 1)

def emit_annotations_error(self, name, depth):
self.emit("if (!cond) {", depth)
Expand Down Expand Up @@ -968,9 +970,9 @@ def visitModule(self, mod):
}
}
Py_ssize_t size = PySet_Size(remaining_fields);
PyObject *annotations = NULL, *remaining_list = NULL;
PyObject *field_types = NULL, *remaining_list = NULL;
if (size > 0) {
if (!_PyObject_LookupAttr((PyObject*)Py_TYPE(self), &_Py_ID(__annotations__), &annotations)) {
if (!_PyObject_LookupAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types), &field_types)) {
res = -1;
goto cleanup;
}
Expand All @@ -980,7 +982,7 @@ def visitModule(self, mod):
}
for (Py_ssize_t i = 0; i < size; i++) {
PyObject *name = PyList_GET_ITEM(remaining_list, i);
PyObject *type = PyDict_GetItemWithError(annotations, name);
PyObject *type = PyDict_GetItemWithError(field_types, name);
if (!type) {
if (!PyErr_Occurred()) {
PyErr_SetObject(PyExc_KeyError, name);
Expand Down Expand Up @@ -1022,7 +1024,7 @@ def visitModule(self, mod):
return res;
set_remaining_cleanup:
Py_XDECREF(remaining_list);
Py_XDECREF(annotations);
Py_XDECREF(field_types);
res = -1;
goto cleanup;
}
Expand Down
Loading
0