summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-10-18 19:56:17 +0000
committerTim Peters <tim.peters@gmail.com>2001-10-18 19:56:17 +0000
commit42369cb8bab3dcbd3b5e71c6220721ac26b6c73d (patch)
treeb2ffc289a9d92485141e700a63977cf9ca63923c
parentf2de631a1a9745a712d5de293b59697f5cd9ec73 (diff)
downloadcpython-42369cb8bab3dcbd3b5e71c6220721ac26b6c73d.tar.gz
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.
-rwxr-xr-xLib/pydoc.py7
-rw-r--r--Lib/test/pydocfodder.py31
2 files changed, 35 insertions, 3 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 1e333398b8..911291b2e8 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -486,7 +486,7 @@ TT { font-family: lucidatypewriter, lucida console, courier }
entry, modname, c)
return '<dl>\n%s</dl>\n' % result
- def docmodule(self, object, name=None, mod=None):
+ def docmodule(self, object, name=None, mod=None, *ignored):
"""Produce HTML documentation for a module object."""
name = object.__name__ # ignore the passed-in name
parts = split(name, '.')
@@ -601,7 +601,8 @@ TT { font-family: lucidatypewriter, lucida console, courier }
return result
- def docclass(self, object, name=None, mod=None, funcs={}, classes={}):
+ def docclass(self, object, name=None, mod=None, funcs={}, classes={},
+ *ignored):
"""Produce HTML documentation for a class object."""
realname = object.__name__
name = name or realname
@@ -800,7 +801,7 @@ TT { font-family: lucidatypewriter, lucida console, courier }
doc = doc and '<dd><tt>%s</tt></dd>' % doc
return '<dl><dt>%s</dt>%s</dl>\n' % (decl, doc)
- def docother(self, object, name=None, mod=None):
+ def docother(self, object, name=None, mod=None, *ignored):
"""Produce HTML documentation for a data object."""
lhs = name and '<strong>%s</strong> = ' % name or ''
return lhs + self.repr(object)
diff --git a/Lib/test/pydocfodder.py b/Lib/test/pydocfodder.py
index 7ccac5e40f..becdf2250e 100644
--- a/Lib/test/pydocfodder.py
+++ b/Lib/test/pydocfodder.py
@@ -177,3 +177,34 @@ class D_new(B_new, C_new):
"Method defined in C and D."
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')