mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Close #14846: Handle a sys.path entry going away
This commit is contained in:
parent
db7920b978
commit
48fec05391
4 changed files with 957 additions and 937 deletions
|
@ -1367,7 +1367,11 @@ class FileFinder:
|
||||||
def _fill_cache(self):
|
def _fill_cache(self):
|
||||||
"""Fill the cache of potential modules and packages for this directory."""
|
"""Fill the cache of potential modules and packages for this directory."""
|
||||||
path = self.path
|
path = self.path
|
||||||
contents = _os.listdir(path)
|
try:
|
||||||
|
contents = _os.listdir(path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
# Directory has been removed since last import
|
||||||
|
contents = []
|
||||||
# We store two cached versions, to handle runtime changes of the
|
# We store two cached versions, to handle runtime changes of the
|
||||||
# PYTHONCASEOK environment variable.
|
# PYTHONCASEOK environment variable.
|
||||||
if not sys.platform.startswith('win'):
|
if not sys.platform.startswith('win'):
|
||||||
|
|
|
@ -35,13 +35,15 @@ class FinderTests(abc.FinderTests):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def import_(self, root, module):
|
def get_finder(self, root):
|
||||||
loader_details = [(machinery.SourceFileLoader,
|
loader_details = [(machinery.SourceFileLoader,
|
||||||
machinery.SOURCE_SUFFIXES),
|
machinery.SOURCE_SUFFIXES),
|
||||||
(machinery.SourcelessFileLoader,
|
(machinery.SourcelessFileLoader,
|
||||||
machinery.BYTECODE_SUFFIXES)]
|
machinery.BYTECODE_SUFFIXES)]
|
||||||
finder = machinery.FileFinder(root, *loader_details)
|
return machinery.FileFinder(root, *loader_details)
|
||||||
return finder.find_module(module)
|
|
||||||
|
def import_(self, root, module):
|
||||||
|
return self.get_finder(root).find_module(module)
|
||||||
|
|
||||||
def run_test(self, test, create=None, *, compile_=None, unlink=None):
|
def run_test(self, test, create=None, *, compile_=None, unlink=None):
|
||||||
"""Test the finding of 'test' with the creation of modules listed in
|
"""Test the finding of 'test' with the creation of modules listed in
|
||||||
|
@ -137,6 +139,13 @@ class FinderTests(abc.FinderTests):
|
||||||
finder.invalidate_caches()
|
finder.invalidate_caches()
|
||||||
self.assertEqual(finder._path_mtime, -1)
|
self.assertEqual(finder._path_mtime, -1)
|
||||||
|
|
||||||
|
# Regression test for http://bugs.python.org/issue14846
|
||||||
|
def test_dir_removal_handling(self):
|
||||||
|
mod = 'mod'
|
||||||
|
with source_util.create_modules(mod) as mapping:
|
||||||
|
finder = self.get_finder(mapping['.root'])
|
||||||
|
self.assertIsNotNone(finder.find_module(mod))
|
||||||
|
self.assertIsNone(finder.find_module(mod))
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
from test.support import run_unittest
|
from test.support import run_unittest
|
||||||
|
|
|
@ -13,6 +13,9 @@ Core and Builtins
|
||||||
- Issue #15604: Update uses of PyObject_IsTrue() to check for and handle
|
- Issue #15604: Update uses of PyObject_IsTrue() to check for and handle
|
||||||
errors correctly. Patch by Serhiy Storchaka.
|
errors correctly. Patch by Serhiy Storchaka.
|
||||||
|
|
||||||
|
- Issue #14846: importlib.FileFinder now handles the case where the
|
||||||
|
directory being searched is removed after a previous import attempt
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
1870
Python/importlib.h
1870
Python/importlib.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue