summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c24
1 files changed, 2 insertions, 22 deletions
diff --git a/Python/import.c b/Python/import.c
index fcc0346..7ce89cd 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -249,16 +249,7 @@ import_get_module(PyThreadState *tstate, PyObject *name)
PyObject *m;
Py_INCREF(modules);
- if (PyDict_CheckExact(modules)) {
- m = PyDict_GetItemWithError(modules, name); /* borrowed */
- Py_XINCREF(m);
- }
- else {
- m = PyObject_GetItem(modules, name);
- if (m == NULL && _PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
- _PyErr_Clear(tstate);
- }
- }
+ (void)PyMapping_GetOptionalItem(modules, name, &m);
Py_DECREF(modules);
return m;
}
@@ -322,18 +313,7 @@ import_add_module(PyThreadState *tstate, PyObject *name)
}
PyObject *m;
- if (PyDict_CheckExact(modules)) {
- m = Py_XNewRef(PyDict_GetItemWithError(modules, name));
- }
- else {
- m = PyObject_GetItem(modules, name);
- // For backward-compatibility we copy the behavior
- // of PyDict_GetItemWithError().
- if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
- _PyErr_Clear(tstate);
- }
- }
- if (_PyErr_Occurred(tstate)) {
+ if (PyMapping_GetOptionalItem(modules, name, &m) < 0) {
return NULL;
}
if (m != NULL && PyModule_Check(m)) {