bpo-44486: Make sure that modules always have a dictionary. (GH-26847)

* Make sure that modules always have a dictionary.
This commit is contained in:
Mark Shannon 2021-06-23 10:00:43 +01:00 committed by GitHub
parent 35b773accb
commit c3f52b4d70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 52 deletions

View file

@ -22,8 +22,8 @@ class ModuleTests(unittest.TestCase):
# An uninitialized module has no __dict__ or __name__,
# and __doc__ is None
foo = ModuleType.__new__(ModuleType)
self.assertTrue(foo.__dict__ is None)
self.assertRaises(TypeError, dir, foo)
self.assertTrue(isinstance(foo.__dict__, dict))
self.assertEqual(dir(foo), [])
try:
s = foo.__name__
self.fail("__name__ = %s" % repr(s))
@ -318,15 +318,6 @@ a = A(destroyed)"""
del foo.__dict__['__annotations__']
def test_annotations_getset_raises(self):
# module has no dict, all operations fail
foo = ModuleType.__new__(ModuleType)
with self.assertRaises(TypeError):
print(foo.__annotations__)
with self.assertRaises(TypeError):
foo.__annotations__ = {}
with self.assertRaises(TypeError):
del foo.__annotations__
# double delete
foo = ModuleType("foo")
foo.__annotations__ = {}