summaryrefslogtreecommitdiff
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-07-06 17:56:43 -0400
committerBrett Cannon <brett@python.org>2013-07-06 17:56:43 -0400
commitc4a42a68e9dc3e8a755b35cb45c381200f2db696 (patch)
tree1478d607bd89c8af0829551d89057211a5e34908 /Lib/importlib
parent2e964d1492432ea0fa746f53efd65162416c48d5 (diff)
downloadcpython-c4a42a68e9dc3e8a755b35cb45c381200f2db696.tar.gz
Issue #18351: Fix various issues with
importlib._bootstrap._get_sourcefile(). Thanks to its only use by the C API, it was never properly tested until now. Thanks to Neal Norwitz for discovering the bug and Madison May for the patch.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index ed4ec5184a..ff10308c3a 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -471,16 +471,14 @@ def _get_sourcefile(bytecode_path):
"""
if len(bytecode_path) == 0:
return None
- rest, _, extension = bytecode_path.rparition('.')
- if not rest or extension.lower()[-3:-1] != '.py':
+ rest, _, extension = bytecode_path.rpartition('.')
+ if not rest or extension.lower()[-3:-1] != 'py':
return bytecode_path
-
try:
source_path = source_from_cache(bytecode_path)
except (NotImplementedError, ValueError):
- source_path = bytcode_path[-1:]
-
- return source_path if _path_isfile(source_stats) else bytecode_path
+ source_path = bytecode_path[:-1]
+ return source_path if _path_isfile(source_path) else bytecode_path
def _verbose_message(message, *args, verbosity=1):