]> granicus.if.org Git - python/commitdiff
[3.6] 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:23:36 +0000 (11:23 -0700)
committerGitHub <noreply@github.com>
Fri, 23 Jun 2017 18:23:36 +0000 (11:23 -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 781ff23d2521611ea70a8c2d46629c9da5878097..866464b245b24c5de4503a055813dcd6b63a741e 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 03f9ea6cc97ae313bc6f29673700f224b966f483..c68f9eb9f1886779e60d7abe6e660e20fa5d3947 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 94a29d0363c6adee4bca29a3ffc7b8b6ee14b0f8..371dcf8ff0d0ac9bba5c2ab52d96aee5d36da7a8 100644 (file)
--- 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.