Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-93461: Invalidate sys.path_importer_cache entries with relative paths #93653

Merged
merged 4 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix and add test cases
  • Loading branch information
tiran committed Jun 9, 2022
commit 98f63aaea2e2fe3053241ac0fa355b82d508080d
14 changes: 12 additions & 2 deletions Lib/test/test_importlib/import_/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ def __init__(self):
def invalidate_caches(self):
self.called = True

cache = {'leave_alone': object(), 'finder_to_invalidate': FakeFinder()}
cache = {'leave_alone': object(), '/finder_to_invalidate': FakeFinder()}
with util.import_state(path_importer_cache=cache):
self.machinery.PathFinder.invalidate_caches()
self.assertTrue(cache['finder_to_invalidate'].called)
self.assertTrue(cache['/finder_to_invalidate'].called)

def test_invalidate_caches_clear_out_None(self):
# Clear out None in sys.path_importer_cache() when invalidating caches.
Expand All @@ -214,6 +214,16 @@ def test_invalidate_caches_clear_out_None(self):
self.machinery.PathFinder.invalidate_caches()
self.assertEqual(len(cache), 0)

def test_invalidate_caches_clear_out_relative_path(self):
class FakeFinder:
def invalidate_caches(self):
pass

cache = {'relative_path': FakeFinder()}
with util.import_state(path_importer_cache=cache):
self.machinery.PathFinder.invalidate_caches()
self.assertEqual(cache, {})


class FindModuleTests(FinderTests):
def find(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_importlib/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def find_module(self, *args):
def invalidate_caches(self):
self.called = True

key = 'gobledeegook'
key = '/gobledeegook'
meta_ins = InvalidatingNullFinder()
path_ins = InvalidatingNullFinder()
sys.meta_path.insert(0, meta_ins)
Expand Down