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:
Brett Cannon 2013-03-13 11:09:08 -07:00
parent 542308eae7
commit 327992330e
4 changed files with 26 additions and 1 deletions

View file

@ -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'