Disallow class assignment completely unless both old and new are heap

types.  This prevents nonsense like 2.__class__ = bool or
True.__class__ = int.
This commit is contained in:
Guido van Rossum 2002-08-10 05:42:07 +00:00
parent e05f65a0c6
commit 40af889081
2 changed files with 14 additions and 6 deletions

View file

@ -2478,6 +2478,11 @@ def setclass():
cant(C(), object)
cant(object(), list)
cant(list(), object)
class Int(int): __slots__ = []
cant(2, Int)
cant(Int(), int)
cant(True, int)
cant(2, bool)
def setdict():
if verbose: print "Testing __dict__ assignment..."