mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
bpo-28411: Support other mappings in PyInterpreterState.modules. (#3593)
The concrete PyDict_* API is used to interact with PyInterpreterState.modules in a number of places. This isn't compatible with all dict subclasses, nor with other Mapping implementations. This patch switches the concrete API usage to the corresponding abstract API calls. We also add a PyImport_GetModule() function (and some other helpers) to reduce a bunch of code duplication.
This commit is contained in:
parent
e82c034496
commit
3f9eee6eb4
11 changed files with 216 additions and 113 deletions
|
@ -38,7 +38,6 @@ static PyObject *
|
|||
get_warnings_attr(const char *attr, int try_import)
|
||||
{
|
||||
static PyObject *warnings_str = NULL;
|
||||
PyObject *all_modules;
|
||||
PyObject *warnings_module, *obj;
|
||||
|
||||
if (warnings_str == NULL) {
|
||||
|
@ -58,13 +57,9 @@ get_warnings_attr(const char *attr, int try_import)
|
|||
}
|
||||
}
|
||||
else {
|
||||
all_modules = PyImport_GetModuleDict();
|
||||
|
||||
warnings_module = PyDict_GetItem(all_modules, warnings_str);
|
||||
warnings_module = PyImport_GetModule(warnings_str);
|
||||
if (warnings_module == NULL)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF(warnings_module);
|
||||
}
|
||||
|
||||
if (!PyObject_HasAttrString(warnings_module, attr)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue