[Python-checkins] CVS: python/dist/src/Lib/test pydocfodder.py,1.2,1.3
Tim Peters
tim_one@users.sourceforge.net
2001年10月18日 12:56:19 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv27875/python/Lib/test
Modified Files:
pydocfodder.py
Log Message:
SF bug [#472347] pydoc and properties.
The GUI-mode code to display properties blew up if the property functions
(get, set, etc) weren't simply methods (or functions).
"The problem" here is really that the generic document() method dispatches
to one of .doc{routine, class, module, other}(), but all of those require
a different(!) number of arguments. Thus document isn't general-purpose
at all: you have to know exactly what kind of thing is it you're going
to document first, in order to pass the correct number of arguments to
.document for it to pass on. As an expedient hack, just tacked "*ignored"
on to the end of the formal argument lists for the .docXXX routines so
that .document's caller doesn't have to know in advance which path
.document is going to take.
Index: pydocfodder.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/pydocfodder.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pydocfodder.py 2001年10月15日 22:59:59 1.2
--- pydocfodder.py 2001年10月18日 19:56:17 1.3
***************
*** 178,179 ****
--- 178,210 ----
def D_method(self):
"Method defined in D."
+
+ class FunkyProperties(object):
+ """From SF bug 472347, by Roeland Rengelink.
+
+ Property getters etc may not be vanilla functions or methods,
+ and this used to make GUI pydoc blow up.
+ """
+
+ def __init__(self):
+ self.desc = {'x':0}
+
+ class get_desc:
+ def __init__(self, attr):
+ self.attr = attr
+ def __call__(self, inst):
+ print 'Get called', self, inst
+ return inst.desc[self.attr]
+ class set_desc:
+ def __init__(self, attr):
+ self.attr = attr
+ def __call__(self, inst, val):
+ print 'Set called', self, inst, val
+ inst.desc[self.attr] = val
+ class del_desc:
+ def __init__(self, attr):
+ self.attr = attr
+ def __call__(self, inst):
+ print 'Del called', self, inst
+ del inst.desc[self.attr]
+
+ x = property(get_desc('x'), set_desc('x'), del_desc('x'), 'prop x')