[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 c38e32a100)
This commit is contained in:
Brett Cannon 2017-06-23 11:23:36 -07:00 committed by GitHub
parent e7135751b8
commit 9db3ae045d
3 changed files with 8 additions and 2 deletions

View file

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

View file

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

View file

@ -101,6 +101,10 @@ Library
variable-argument parameters wrapped with partialmethod. variable-argument parameters wrapped with partialmethod.
Patch by Dong-hee Na. Patch by Dong-hee Na.
- 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-29931: Fixed comparison check for ipaddress.ip_interface objects. - bpo-29931: Fixed comparison check for ipaddress.ip_interface objects.
Patch by Sanjay Sundaresan. Patch by Sanjay Sundaresan.