From 9005c796078d5ce0b8c2758d7334d95e501845ec Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Fri, 23 Jun 2017 20:35:03 +0300 Subject: [PATCH 1/2] 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. (cherry picked from commit c38e32a10061a7c6d54e7e53ffabf7af7998f045) --- Lib/imp.py | 5 +++-- Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/imp.py b/Lib/imp.py index 781ff23d2521611..866464b245b24c5 100644 --- a/Lib/imp.py +++ b/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)) diff --git a/Misc/ACKS b/Misc/ACKS index 03f9ea6cc97ae31..c68f9eb9f188677 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -56,6 +56,7 @@ Ankur Ankan Heidi Annexstad Ramchandra Apte Éric Araujo +Alexandru Ardelean Alicia Arlen Jeffrey Armstrong Jason Asbahr diff --git a/Misc/NEWS b/Misc/NEWS index 94a29d0363c6ade..371dcf8ff0d0ac9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -101,6 +101,10 @@ Library variable-argument parameters wrapped with partialmethod. 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. Patch by Sanjay Sundaresan. From 693187c80ab96178b9affb11591258081c356790 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 23 Jun 2017 10:44:37 -0700 Subject: [PATCH 2/2] [3.6] 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.. (cherry picked from commit c38e32a10061a7c6d54e7e53ffabf7af7998f045)