Skip to content

Commit ddfe7a0

Browse files
committed
Issue #24285: fix importing extensions from packages
1 parent 0bc0bbf commit ddfe7a0

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lib/test/test_importlib/extension/test_loader.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ def load_module_by_name(self, fullname):
170170
loader.exec_module(module)
171171
return module
172172

173+
def test_load_submodule(self):
174+
'''Test loading a simulated submodule'''
175+
module = self.load_module_by_name('pkg.' + self.name)
176+
self.assertIsInstance(module, types.ModuleType)
177+
self.assertEqual(module.__name__, 'pkg.' + self.name)
178+
self.assertEqual(module.str_const, 'something different')
179+
173180
def test_load_twice(self):
174181
'''Test that 2 loads result in 2 module objects'''
175182
module1 = self.load_module_by_name(self.name)

Misc/NEWS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: 2015-07-05
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #24285: Fixed regression that prevented importing extension modules
14+
from inside packages. Patch by Petr Viktorin.
15+
1316
Library
1417
-------
1518

@@ -24,7 +27,8 @@ Core and Builtins
2427

2528
- Issue #24276: Fixed optimization of property descriptor getter.
2629

27-
- Issue #24268: PEP 489: Multi-phase extension module initialization
30+
- Issue #24268: PEP 489: Multi-phase extension module initialization.
31+
Patch by Petr Viktorin.
2832

2933
- Issue #23955: Add pyvenv.cfg option to suppress registry/environment
3034
lookup for generating sys.path on Windows.

Python/importdl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) {
4545
if (lastdot < -1) {
4646
return NULL;
4747
} else if (lastdot >= 0) {
48-
tmp = PyUnicode_Substring(name, lastdot, name_len);
48+
tmp = PyUnicode_Substring(name, lastdot + 1, name_len);
4949
if (tmp == NULL)
5050
return NULL;
5151
name = tmp;

0 commit comments

Comments
 (0)