Commits

Christoph Reiter  committed 939ce8f

Use PyImport_ImportModuleLevel in PyImport_ImportModuleEx directly; Fix wrapped variable naming; Improve test

  • Participants
  • Parent commits 36b875a
  • Branches cpyext-import-ex

Comments (0)

Files changed (2)

File pypy/module/cpyext/import_.py

 
     The function is an alias for PyImport_ImportModuleLevel() with -1 as level,
     meaning relative import."""
-    caller = space.getexecutioncontext().gettopframe_nohidden()
-    if caller is not None:
-        w_builtin = space.getitem(w_globals, space.wrap('__builtins__'))
-    else:
-        w_builtin = space.getbuiltinmodule('__builtin__')
-
-    return _import(space, w_builtin, w_name, w_globals, w_locals,
-                   w_fromlist, space.wrap(-1))
+    return PyImport_ImportModuleLevel(space, w_name, w_globals, w_locals, w_fromlist, space.wrap(-1))
 
 @cpython_api([PyObject], PyObject)
 def PyImport_Import(space, w_name):

File pypy/module/cpyext/test/test_import.py

         assert space.getattr(stat, space.wrap("S_IMODE"))
 
     def test_import_ext(self, space, api):
-        ospath_w = api.PyImport_ImportModuleEx(
+        w_ospath = api.PyImport_ImportModuleEx(
             space.wrap("os.path"), None, None, space.wrap(["foo"]))
-        assert ospath_w
+        assert w_ospath
 
         import os.path as ospath
-        assert space.unwrap(space.getattr(ospath_w, space.wrap('__name__'))) == ospath.__name__
+        assert space.unwrap(space.getattr(w_ospath, space.wrap('__name__'))) == ospath.__name__
 
     def test_import_module_level(self, space, api):
-        stat = api.PyImport_ImportModuleLevel(
+        w_stat = api.PyImport_ImportModuleLevel(
             space.wrap("stat"), None, None, space.newdict(), space.wrap(0))
-        assert stat
+        assert w_stat
+        assert w_stat is space.getitem(space.sys.get("modules"), space.wrap("stat"))
 
     def test_addmodule(self, space, api):
         with rffi.scoped_str2charp("sys") as modname: