summaryrefslogtreecommitdiff
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2017-09-15 16:35:20 -0600
committerGitHub <noreply@github.com>2017-09-15 16:35:20 -0600
commit3f9eee6eb4b25fe1926eaa5f00e02344b126f54d (patch)
treec749747e0b4ce492d05c34ad5578b81128be1156 /Python/_warnings.c
parente82c034496512139e9ea3f68ceda86c04bc7baab (diff)
downloadcpython-git-3f9eee6eb4b25fe1926eaa5f00e02344b126f54d.tar.gz
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.
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index ba004859df..f6688b0406 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -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)) {