bpo-46891: Fix creating a new instance of a module subclass with slots (GH-31643)

This commit is contained in:
Mark Shannon 2022-03-03 10:38:27 +00:00 committed by GitHub
parent 3c4abfab0d
commit 751c9ed801
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -346,6 +346,25 @@ a = A(destroyed)"""
# frozen and namespace module reprs are tested in importlib.
def test_subclass_with_slots(self):
# In 3.11alpha this crashed, as the slots weren't NULLed.
class ModuleWithSlots(ModuleType):
__slots__ = ("a", "b")
def __init__(self, name):
super().__init__(name)
m = ModuleWithSlots("name")
with self.assertRaises(AttributeError):
m.a
with self.assertRaises(AttributeError):
m.b
m.a, m.b = 1, 2
self.assertEqual(m.a, 1)
self.assertEqual(m.b, 2)
if __name__ == '__main__':
unittest.main()