mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
Issue #17099: Have importlib.find_loader() raise ValueError when
__loader__ is not set on a module. This brings the exception in line with when __loader__ is None (which is equivalent to not having the attribute defined).
This commit is contained in:
parent
542308eae7
commit
327992330e
4 changed files with 26 additions and 1 deletions
|
@ -116,6 +116,20 @@ class FindLoaderTests(unittest.TestCase):
|
|||
with self.assertRaises(ValueError):
|
||||
importlib.find_loader(name)
|
||||
|
||||
def test_sys_modules_loader_is_not_set(self):
|
||||
# Should raise ValueError
|
||||
# Issue #17099
|
||||
name = 'some_mod'
|
||||
with util.uncache(name):
|
||||
module = imp.new_module(name)
|
||||
try:
|
||||
del module.__loader__
|
||||
except AttributeError:
|
||||
pass
|
||||
sys.modules[name] = module
|
||||
with self.assertRaises(ValueError):
|
||||
importlib.find_loader(name)
|
||||
|
||||
def test_success(self):
|
||||
# Return the loader found on sys.meta_path.
|
||||
name = 'some_mod'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue