[Python-checkins] python/dist/src/Lib/test test_descr.py,1.131,1.132
gvanrossum@sourceforge.net
gvanrossum@sourceforge.net
Wed, 17 Apr 2002 17:27:35 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv6764
Modified Files:
test_descr.py
Log Message:
SF bug 542984.
Change type_get_doc (the get function for __doc__) to look in tp_dict
more often, and if it finds a descriptor in tp_dict, to call it (with
a NULL instance). This means you can add a __doc__ descriptor to a
new-style class that returns instance docs when called on an instance,
and class docs when called on a class -- or the same docs in either
case, but lazily computed.
I'll also check this into the 2.2 maintenance branch.
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.131
retrieving revision 1.132
diff -C2 -d -r1.131 -r1.132
*** test_descr.py 16 Apr 2002 16:44:51 -0000 1.131
--- test_descr.py 18 Apr 2002 00:27:33 -0000 1.132
***************
*** 2956,2959 ****
--- 2956,2978 ----
vereq(y, (x, "foo"))
+ def docdescriptor():
+ # SF bug 542984
+ if verbose: print "Testing __doc__ descriptor..."
+ class DocDescr(object):
+ def __get__(self, object, otype):
+ if object:
+ object = object.__class__.__name__ + ' instance'
+ if otype:
+ otype = otype.__name__
+ return 'object=%s; type=%s' % (object, otype)
+ class OldClass:
+ __doc__ = DocDescr()
+ class NewClass(object):
+ __doc__ = DocDescr()
+ vereq(OldClass.__doc__, 'object=None; type=OldClass')
+ vereq(OldClass().__doc__, 'object=OldClass instance; type=OldClass')
+ vereq(NewClass.__doc__, 'object=None; type=NewClass')
+ vereq(NewClass().__doc__, 'object=NewClass instance; type=NewClass')
+
def test_main():
class_docstrings()
***************
*** 3020,3023 ****
--- 3039,3043 ----
funnynew()
imulbug()
+ docdescriptor()
if verbose: print "All OK"