summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-03-07 09:21:08 (GMT)
committerGitHub <noreply@github.com>2024-03-07 09:21:08 (GMT)
commit72d3cc94cd8cae1925e7a14f297b06ac6184f916 (patch)
treedf9d7a5a97a79f97065282dd8e5a89f57ea2e18b /Parser
parent882fcede83af783a834b759e4643130dc1307ee3 (diff)
downloadcpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.zip
cpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.tar.gz
cpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.tar.bz2
gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)
Diffstat (limited to 'Parser')
-rwxr-xr-xParser/asdl_c.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 865fd76..59cc391 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -1077,20 +1077,20 @@ ast_type_reduce(PyObject *self, PyObject *unused)
if (!name) {
goto cleanup;
}
- PyObject *value = PyDict_GetItemWithError(remaining_dict, name);
+ PyObject *value;
+ int rc = PyDict_Pop(remaining_dict, name, &value);
+ Py_DECREF(name);
+ if (rc < 0) {
+ goto cleanup;
+ }
if (!value) {
- if (PyErr_Occurred()) {
- goto cleanup;
- }
break;
}
- if (PyList_Append(positional_args, value) < 0) {
+ rc = PyList_Append(positional_args, value);
+ Py_DECREF(value);
+ if (rc < 0) {
goto cleanup;
}
- if (PyDict_DelItem(remaining_dict, name) < 0) {
- goto cleanup;
- }
- Py_DECREF(name);
}
PyObject *args_tuple = PyList_AsTuple(positional_args);
if (!args_tuple) {