summaryrefslogtreecommitdiffstats
path: root/Lib/imp.py
diff options
context:
space:
mode:
authorAlexandru Ardelean <ardeleanalex@gmail.com>2017-06-23 17:35:03 (GMT)
committerBrett Cannon <brettcannon@users.noreply.github.com>2017-06-23 17:35:03 (GMT)
commitc38e32a10061a7c6d54e7e53ffabf7af7998f045 (patch)
tree4a483af1b13929282fa42aeb90e9b1da5247b952 /Lib/imp.py
parentd174d24a5d37d1516b885dc7c82f71ecd5930700 (diff)
downloadcpython-c38e32a10061a7c6d54e7e53ffabf7af7998f045.zip
cpython-c38e32a10061a7c6d54e7e53ffabf7af7998f045.tar.gz
cpython-c38e32a10061a7c6d54e7e53ffabf7af7998f045.tar.bz2
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.
Diffstat (limited to 'Lib/imp.py')
-rw-r--r--Lib/imp.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/imp.py b/Lib/imp.py
index 781ff23..866464b 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))