mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
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.
This commit is contained in:
parent
2a99d5df63
commit
a53cca3fea
5 changed files with 3446 additions and 3407 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue