mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #12599: Be more strict in accepting None vs. a false-like object
in importlib. Thanks to PJE for pointing out the issue and Nick Coghlan for filing the bug.
This commit is contained in:
parent
64befe939c
commit
7bd329d800
5 changed files with 1240 additions and 1212 deletions
|
@ -65,8 +65,22 @@ class ModuleForLoaderTests(unittest.TestCase):
|
|||
self.assertEqual(wrapped.__name__, fxn.__name__)
|
||||
self.assertEqual(wrapped.__qualname__, fxn.__qualname__)
|
||||
|
||||
class SetPackageTests(unittest.TestCase):
|
||||
def test_false_module(self):
|
||||
# If for some odd reason a module is considered false, still return it
|
||||
# from sys.modules.
|
||||
class FalseModule(types.ModuleType):
|
||||
def __bool__(self): return False
|
||||
|
||||
name = 'mod'
|
||||
module = FalseModule(name)
|
||||
with test_util.uncache(name):
|
||||
self.assertFalse(module)
|
||||
sys.modules[name] = module
|
||||
given = self.return_module(name)
|
||||
self.assertTrue(given is module)
|
||||
|
||||
|
||||
class SetPackageTests(unittest.TestCase):
|
||||
|
||||
"""Tests for importlib.util.set_package."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue