Mailing List Archive

python/dist/src/Lib/test test_descr.py,1.162,1.163
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv18876/Lib/test

Modified Files:
test_descr.py
Log Message:
This is my patch:

[ 635933 ] make some type attrs writable

Plus a couple of extra tests beyond what's up there.

It hasn't been as carefully reviewed as it perhaps should, so all readers
are encouraged, nay exhorted, to give this a close reading.

There are still a couple of oddities related to assigning to __name__,
but I intend to solicit python-dev's opinions on these.


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.162
retrieving revision 1.163
diff -C2 -d -r1.162 -r1.163
*** test_descr.py 25 Nov 2002 21:38:52 -0000 1.162
--- test_descr.py 26 Nov 2002 14:47:27 -0000 1.163
***************
*** 3435,3438 ****
--- 3435,3525 ----
type.mro(tuple)

+ def mutable_bases():
+ # stuff that should work:
+ class C(object):
+ pass
+ class C2(object):
+ def __getattribute__(self, attr):
+ if attr == 'a':
+ return 2
+ else:
+ return super(C2, self).__getattribute__(attr)
+ def meth(self):
+ return 1
+ class D(C):
+ pass
+ class E(D):
+ pass
+ d = D()
+ e = E()
+ D.__bases__ = (C2,)
+ vereq(d.meth(), 1)
+ vereq(e.meth(), 1)
+ vereq(d.a, 2)
+ vereq(e.a, 2)
+ vereq(C2.__subclasses__(), [D])
+
+ # stuff that shouldn't:
+ class L(list):
+ pass
+
+ try:
+ L.__bases__ = (dict,)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "shouldn't turn list subclass into dict subclass"
+
+ try:
+ list.__bases__ = (dict,)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "shouldn't be able to assign to list.__bases__"
+
+ try:
+ del D.__bases__
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "shouldn't be able to delete .__bases__"
+
+ try:
+ D.__bases__ = (D,)
+ except TypeError:
+ pass
+ else:
+ # actually, we'll have crashed by here...
+ raise TestFailed, "shouldn't be able to create inheritance cycles"
+
+ # let's throw a classic class into the mix:
+ class Classic:
+ def meth2(self):
+ return 3
+
+ D.__bases__ = (C, Classic)
+
+ vereq(d.meth2(), 3)
+ vereq(e.meth2(), 3)
+ try:
+ d.a
+ except AttributeError:
+ pass
+ else:
+ raise TestFailed, "attribute should have vanished"
+
+ try:
+ D.__bases__ = (Classic,)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "new-style class must have a new-style base"
+
+ def mutable_names():
+ class C(object):
+ pass
+
+ C.__name__ = 'C'
+
def test_main():
do_this_first()
***************
*** 3514,3517 ****
--- 3601,3606 ----
testrmul()
testipow()
+ mutable_bases()
+ mutable_names()
if verbose: print "All OK"