summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-04-18 00:27:33 (GMT)
committerGuido van Rossum <guido@python.org>2002-04-18 00:27:33 (GMT)
commitd99b3e78dd3160124816fb77e59af1f1682a2472 (patch)
tree19c38c606aab849c68d2c93632beb7cf5dff3b30 /Lib/test
parent6ca7d41c1f0f2f6ef654f3ff6241c80cccf06ab3 (diff)
downloadcpython-d99b3e78dd3160124816fb77e59af1f1682a2472.zip
cpython-d99b3e78dd3160124816fb77e59af1f1682a2472.tar.gz
cpython-d99b3e78dd3160124816fb77e59af1f1682a2472.tar.bz2
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.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_descr.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index fc5f2ea..308ed44 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2955,6 +2955,25 @@ def imulbug():
y *= "foo"
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()
lists()
@@ -3019,6 +3038,7 @@ def test_main():
pickleslots()
funnynew()
imulbug()
+ docdescriptor()
if verbose: print "All OK"
if __name__ == "__main__":