Browse Source

bpo-30645: don't append to an inner loop path in imp.load_package() (GH-2268)

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.
pull/2366/head
Alexandru Ardelean 9 years ago
committed by Brett Cannon
parent
commit
c38e32a100
  1. 5
      Lib/imp.py
  2. 1
      Misc/ACKS
  3. 4
      Misc/NEWS

5
Lib/imp.py

@ -203,8 +203,9 @@ def load_package(name, path):
extensions = (machinery.SOURCE_SUFFIXES[:] +
machinery.BYTECODE_SUFFIXES[:])
for extension in extensions:
path = os.path.join(path, '__init__'+extension)
if os.path.exists(path):
init_path = os.path.join(path, '__init__' + extension)
if os.path.exists(init_path):
path = init_path
break
else:
raise ValueError('{!r} is not a package'.format(path))

1
Misc/ACKS

@ -57,6 +57,7 @@ Ankur Ankan
Heidi Annexstad
Ramchandra Apte
Éric Araujo
Alexandru Ardelean
Alicia Arlen
Jeffrey Armstrong
Jason Asbahr

4
Misc/NEWS

@ -428,6 +428,10 @@ Library
- bpo-30508: Don't log exceptions if Task/Future "cancel()" method was
called.
- bpo-30645: Fix path calculation in `imp.load_package()`, fixing it for
cases when a package is only shipped with bytecodes. Patch by
Alexandru Ardelean.
- bpo-11822: The dis.dis() function now is able to disassemble nested
code objects.

Loading…
Cancel
Save