summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_module.py
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-03-03 10:38:27 (GMT)
committerGitHub <noreply@github.com>2022-03-03 10:38:27 (GMT)
commit751c9ed801ad1189272ca10f0749bfc9d49b5038 (patch)
treedb17f40d13eadfade31e3133463954c86fe9d6e2 /Lib/test/test_module.py
parent3c4abfab0d3e2a3b1e626a5eb185ad1f5436b532 (diff)
downloadcpython-751c9ed801ad1189272ca10f0749bfc9d49b5038.zip
cpython-751c9ed801ad1189272ca10f0749bfc9d49b5038.tar.gz
cpython-751c9ed801ad1189272ca10f0749bfc9d49b5038.tar.bz2
bpo-46891: Fix creating a new instance of a module subclass with slots (GH-31643)
Diffstat (limited to 'Lib/test/test_module.py')
-rw-r--r--Lib/test/test_module.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py
index 619348e..f72177d 100644
--- a/Lib/test/test_module.py
+++ b/Lib/test/test_module.py
@@ -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()