Skip to content

Commit 599ff02

Browse files
authored
[3.5] bpo-30645: don't append to an inner loop path in imp.load_package() (GH-2268) (GH-2365)
Bug didn't manifest itself when importing a module with source as .py files are always the first on the search path. The issue only showed up in bytecode-only packages where the calculated file path would be ``__init__.py/__init__.pyc``. Patch by Alexandru Ardelean. (cherry picked from commit c38e32a)
1 parent a7c0264 commit 599ff02

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Lib/imp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ def load_package(name, path):
203203
extensions = (machinery.SOURCE_SUFFIXES[:] +
204204
machinery.BYTECODE_SUFFIXES[:])
205205
for extension in extensions:
206-
path = os.path.join(path, '__init__'+extension)
207-
if os.path.exists(path):
206+
init_path = os.path.join(path, '__init__' + extension)
207+
if os.path.exists(init_path):
208+
path = init_path
208209
break
209210
else:
210211
raise ValueError('{!r} is not a package'.format(path))

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Ankur Ankan
5656
Heidi Annexstad
5757
Ramchandra Apte
5858
Éric Araujo
59+
Alexandru Ardelean
5960
Alicia Arlen
6061
Jeffrey Armstrong
6162
Jason Asbahr

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Library
7979
correctly returns the ``127.0.0.1`` host, instead of treating ``@evil.com``
8080
as the host in an authentification (``login@host``).
8181

82+
- bpo-30645: Fix path calculation in imp.load_package(), fixing it for
83+
cases when a package is only shipped with bytecodes. Patch by
84+
Alexandru Ardelean.
85+
8286
- bpo-23890: unittest.TestCase.assertRaises() now manually breaks a reference
8387
cycle to not keep objects alive longer than expected.
8488

0 commit comments

Comments
 (0)