Skip to content

Commit 9db3ae0

Browse files
authored
[3.6] bpo-30645: don't append to an inner loop path in imp.load_package() (GH-2268) (#2364)
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 e713575 commit 9db3ae0

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
@@ -101,6 +101,10 @@ Library
101101
variable-argument parameters wrapped with partialmethod.
102102
Patch by Dong-hee Na.
103103

104+
- bpo-30645: Fix path calculation in imp.load_package(), fixing it for
105+
cases when a package is only shipped with bytecodes. Patch by
106+
Alexandru Ardelean.
107+
104108
- bpo-29931: Fixed comparison check for ipaddress.ip_interface objects.
105109
Patch by Sanjay Sundaresan.
106110

0 commit comments

Comments
 (0)