[New-bugs-announce] [issue18812] PyImport_Import redundant calls to find module

Rob Bairos report at bugs.python.org
Thu Aug 22 21:00:11 CEST 2013


New submission from Rob Bairos:

Why does PyImport_Import (import.c) call __import__ then immediately discard the result, and then look for the module again in the module dictionary?  

It will return the same value in both cases no?

Ive included the relevant portion of the code below.
Its breaking an embedded application we've built where a hierarchy of modules are maintained outside the sys.modules dictionary.


 /* Call the __import__ function with the proper argument list
    Always use absolute import here.
    Calling for side-effect of import. */
 r = PyObject_CallFunction(import, "OOOOi", module_name, globals,
                           globals, silly_list, 0, NULL);
 if (r == NULL)
     goto err;

//-------------------------- WHY IS THIS SECTION NEEDED? --------
 Py_DECREF(r);
 modules = PyImport_GetModuleDict();
 r = PyDict_GetItem(modules, module_name);
 if (r != NULL)
//---------------------------------------------------------------
     Py_INCREF(r);

----------
components: Interpreter Core
messages: 195915
nosy: Rob.Bairos
priority: normal
severity: normal
status: open
title: PyImport_Import redundant calls to find module
versions: Python 3.2, Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18812>
_______________________________________


More information about the New-bugs-announce mailing list