]> granicus.if.org Git - python/commitdiff
[3.5] bpo-30645: don't append to an inner loop path in imp.load_package() (GH-2268...
authorBrett Cannon <brettcannon@users.noreply.github.com>
Fri, 23 Jun 2017 18:39:53 +0000 (11:39 -0700)
committerGitHub <noreply@github.com>
Fri, 23 Jun 2017 18:39:53 +0000 (11:39 -0700)
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
Misc/ACKS
Misc/NEWS

index e2643918421714b2d979d42a59c890b415e02dab..af0790f9422de7a1466ac29db9052da5952ed65c 100644 (file)
@@ -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))
index 45358e7f9b8f2d37612fe9b295444f6d7158d48b..7f9044ac7cb6dab00b80555f4d1bbbdf56de6f54 100644 (file)
--- 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
index b2bbd5d359c2641bbb11c2e92817ea06b89d66b7..b731792cde620648745c23412853c4d206b8691d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -79,6 +79,10 @@ Library
   correctly returns the ``127.0.0.1`` host, instead of treating ``@evil.com``
   as the host in an authentification (``login@host``).
 
+- 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-23890: unittest.TestCase.assertRaises() now manually breaks a reference
   cycle to not keep objects alive longer than expected.