gh-108314: Add PyDict_ContainsString() function (#108323)

This commit is contained in:
Victor Stinner 2023-08-24 15:59:12 +02:00 committed by GitHub
parent c163d7f0b6
commit 6726626646
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 112 additions and 36 deletions

View file

@ -2220,10 +2220,11 @@ add_main_module(PyInterpreterState *interp)
}
Py_DECREF(ann_dict);
if (_PyDict_GetItemStringWithError(d, "__builtins__") == NULL) {
if (PyErr_Occurred()) {
return _PyStatus_ERR("Failed to test __main__.__builtins__");
}
int has_builtins = PyDict_ContainsString(d, "__builtins__");
if (has_builtins < 0) {
return _PyStatus_ERR("Failed to test __main__.__builtins__");
}
if (!has_builtins) {
PyObject *bimod = PyImport_ImportModule("builtins");
if (bimod == NULL) {
return _PyStatus_ERR("Failed to retrieve builtins module");