Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(35)

Unified Diff: Lib/test/test_module.py

Issue 22986: Improved handling of __class__ assignment
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Objects/typeobject.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
index 9da3536..a461743 100644
--- a/Lib/test/test_module.py
+++ b/Lib/test/test_module.py
@@ -235,6 +235,22 @@ a = A(destroyed)"""
melon = Descr()
self.assertRaises(RuntimeError, getattr, M("mymod"), "melon")
+ def test___class___assignment(self):
+ class SubType(ModuleType):
+ a = 1
+
+ m = ModuleType("m")
+ self.assertTrue(m.__class__ is ModuleType)
+ self.assertFalse(hasattr(m, "a"))
+
+ m.__class__ = SubType
+ self.assertTrue(m.__class__ is SubType)
+ self.assertTrue(hasattr(m, "a"))
+
+ m.__class__ = ModuleType
+ self.assertTrue(m.__class__ is ModuleType)
+ self.assertFalse(hasattr(m, "a"))
+
# frozen and namespace module reprs are tested in importlib.
« no previous file with comments | « no previous file | Objects/typeobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+