]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #24285: fix importing extensions from packages
authorNick Coghlan <ncoghlan@gmail.com>
Tue, 26 May 2015 11:48:17 +0000 (21:48 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Tue, 26 May 2015 11:48:17 +0000 (21:48 +1000)
Lib/test/test_importlib/extension/test_loader.py
Misc/NEWS
Python/importdl.c

index 66ac2b12b5139f8c650ad3279bae8a901caea619..5813ade953fdf135b58b0582207ccb575462ae91 100644 (file)
@@ -170,6 +170,13 @@ class MultiPhaseExtensionModuleTests(abc.LoaderTests):
         loader.exec_module(module)
         return module
 
+    def test_load_submodule(self):
+        '''Test loading a simulated submodule'''
+        module = self.load_module_by_name('pkg.' + self.name)
+        self.assertIsInstance(module, types.ModuleType)
+        self.assertEqual(module.__name__, 'pkg.' + self.name)
+        self.assertEqual(module.str_const, 'something different')
+
     def test_load_twice(self):
         '''Test that 2 loads result in 2 module objects'''
         module1 = self.load_module_by_name(self.name)
index e2d01dcdaf997adf7f0c8cf31dfab275018878ab..f3745ac434eb15bc7b758fc6755af3b0e87afc8f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: 2015-07-05
 Core and Builtins
 -----------------
 
+- Issue #24285: Fixed regression that prevented importing extension modules
+  from inside packages. Patch by Petr Viktorin.
+
 Library
 -------
 
@@ -24,7 +27,8 @@ Core and Builtins
 
 - Issue #24276: Fixed optimization of property descriptor getter.
 
-- Issue #24268: PEP 489: Multi-phase extension module initialization
+- Issue #24268: PEP 489: Multi-phase extension module initialization.
+  Patch by Petr Viktorin.
 
 - Issue #23955: Add pyvenv.cfg option to suppress registry/environment
   lookup for generating sys.path on Windows.
index bb90391c0bd1f7849adc0b463a9f373e34597c9e..579d2c5fada8178caedc3a576b45745f295f8555 100644 (file)
@@ -45,7 +45,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) {
     if (lastdot < -1) {
         return NULL;
     } else if (lastdot >= 0) {
-        tmp = PyUnicode_Substring(name, lastdot, name_len);
+        tmp = PyUnicode_Substring(name, lastdot + 1, name_len);
         if (tmp == NULL)
             return NULL;
         name = tmp;