Issue 891637: pydoc crashes on a class property (original) (raw)
[forwarded from http://bugs.debian.org/231202]
class foo(object): slots = ['_bar'] bar = property(lambda (self): self._bar) def init(self, bar): self._bar = bar f = foo(1) assert(f.bar == 1)
removing the parenthesis around the lambda's parameter avoids the pydoc crash. Python itself doesn't seem to care about the parenthesis.
$ python tmp.py # no errors $ pydoc tmp Traceback (most recent call last): File "/usr/bin/pydoc", line 4, in ? pydoc.cli() File "/usr/lib/python2.3/pydoc.py", line 2123, in cli help.help(arg) File "/usr/lib/python2.3/pydoc.py", line 1582, in help elif request: doc(request, 'Help on %s:') File "/usr/lib/python2.3/pydoc.py", line 1375, in doc pager(title % desc + '\n\n' + text.document(object, name)) File "/usr/lib/python2.3/pydoc.py", line 283, in document if inspect.ismodule(object): return self.docmodule(*args) File "/usr/lib/python2.3/pydoc.py", line 990, in docmodule contents.append(self.document(value, key, name)) File "/usr/lib/python2.3/pydoc.py", line 284, in document if inspect.isclass(object): return self.docclass(*args) File "/usr/lib/python2.3/pydoc.py", line 1135, in docclass lambda t: t[1] == 'property') File "/usr/lib/python2.3/pydoc.py", line 1087, in spillproperties base = self.document(func, tag, mod) File "/usr/lib/python2.3/pydoc.py", line 285, in document if inspect.isroutine(object): return self.docroutine(*args) File "/usr/lib/python2.3/pydoc.py", line 1177, in docroutine args, varargs, varkw, defaults = inspect.getargspec(object) File "/usr/lib/python2.3/inspect.py", line 656, in getargspec args, varargs, varkw = getargs(func.func_code) File "/usr/lib/python2.3/inspect.py", line 624, in getargs remain[-1] = remain[-1] - 1 IndexError: list index out of range
Logged In: YES user_id=469548
First, note that the problem doesn't lie in properties. This crashes as well:
foo = lambda (bar): 1
second, Python does care about the parentheses. It just doesn't matter when the lambda has only one argument. Using parentheses creates a sublist instead of a parameter list, as in the following example with normal functions:
def foo((bar, baz)): return bar assert(foo((1, 2)) == 1)
pydoc (or rather, inspect) should still be fixed though.