Skip to content

Commit 42369cb

Browse files
committed
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.
1 parent f2de631 commit 42369cb

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

Lib/pydoc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def formattree(self, tree, modname, parent=None):
486486
entry, modname, c)
487487
return '<dl>\n%s</dl>\n' % result
488488

489-
def docmodule(self, object, name=None, mod=None):
489+
def docmodule(self, object, name=None, mod=None, *ignored):
490490
"""Produce HTML documentation for a module object."""
491491
name = object.__name__ # ignore the passed-in name
492492
parts = split(name, '.')
@@ -601,7 +601,8 @@ def docmodule(self, object, name=None, mod=None):
601601

602602
return result
603603

604-
def docclass(self, object, name=None, mod=None, funcs={}, classes={}):
604+
def docclass(self, object, name=None, mod=None, funcs={}, classes={},
605+
*ignored):
605606
"""Produce HTML documentation for a class object."""
606607
realname = object.__name__
607608
name = name or realname
@@ -800,7 +801,7 @@ def docroutine(self, object, name=None, mod=None,
800801
doc = doc and '<dd><tt>%s</tt></dd>' % doc
801802
return '<dl><dt>%s</dt>%s</dl>\n' % (decl, doc)
802803

803-
def docother(self, object, name=None, mod=None):
804+
def docother(self, object, name=None, mod=None, *ignored):
804805
"""Produce HTML documentation for a data object."""
805806
lhs = name and '<strong>%s</strong> = ' % name or ''
806807
return lhs + self.repr(object)

Lib/test/pydocfodder.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,34 @@ def CD_method(self):
177177
"Method defined in C and D."
178178
def D_method(self):
179179
"Method defined in D."
180+
181+
class FunkyProperties(object):
182+
"""From SF bug 472347, by Roeland Rengelink.
183+
184+
Property getters etc may not be vanilla functions or methods,
185+
and this used to make GUI pydoc blow up.
186+
"""
187+
188+
def __init__(self):
189+
self.desc = {'x':0}
190+
191+
class get_desc:
192+
def __init__(self, attr):
193+
self.attr = attr
194+
def __call__(self, inst):
195+
print 'Get called', self, inst
196+
return inst.desc[self.attr]
197+
class set_desc:
198+
def __init__(self, attr):
199+
self.attr = attr
200+
def __call__(self, inst, val):
201+
print 'Set called', self, inst, val
202+
inst.desc[self.attr] = val
203+
class del_desc:
204+
def __init__(self, attr):
205+
self.attr = attr
206+
def __call__(self, inst):
207+
print 'Del called', self, inst
208+
del inst.desc[self.attr]
209+
210+
x = property(get_desc('x'), set_desc('x'), del_desc('x'), 'prop x')

0 commit comments

Comments
 (0)