classification
Title: help(cls1) breaks when cls1 has staticmethod(cls2) attribute
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: belopolsky, eric.araujo, georg.brandl, milko.krachounov, ncoghlan, ron_adam
Priority: normal Keywords:

Created on 2010-11-27 16:37 by milko.krachounov, last changed 2010-12-03 09:59 by georg.brandl. This issue is now closed.

Messages (4)
msg122535 - (view) Author: Milko Krachounov (milko.krachounov) Date: 2010-11-27 16:37
If I make a class B, and add staticmethod(A) as an attribute when B is another class, help(B) breaks. The issue appears with Python 2.6.6, trunk, 3.1.3c1, and py3k SVN.

Python 2.7 (trunk:86836, Nov 27 2010, 18:23:07) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object):
...     pass
... 
>>> class B(object):
...     attr = staticmethod(A)
... 
>>> help(B)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/milko/Среда/Python/trunk/Lib/site.py", line 453, in __call__
    return pydoc.help(*args, **kwds)
  File "/home/milko/Среда/Python/trunk/Lib/pydoc.py", line 1720, in __call__
    self.help(request)
  File "/home/milko/Среда/Python/trunk/Lib/pydoc.py", line 1767, in help
    else: doc(request, 'Help on %s:')
  File "/home/milko/Среда/Python/trunk/Lib/pydoc.py", line 1508, in doc
    pager(render_doc(thing, title, forceload))
  File "/home/milko/Среда/Python/trunk/Lib/pydoc.py", line 1503, in render_doc
    return title % desc + '\n\n' + text.document(object, name)
  File "/home/milko/Среда/Python/trunk/Lib/pydoc.py", line 327, in document
    if inspect.isclass(object): return self.docclass(*args)
  File "/home/milko/Среда/Python/trunk/Lib/pydoc.py", line 1216, in docclass
    lambda t: t[1] == 'static method')
  File "/home/milko/Среда/Python/trunk/Lib/pydoc.py", line 1162, in spill
    name, mod, object))
  File "/home/milko/Среда/Python/trunk/Lib/pydoc.py", line 327, in document
    if inspect.isclass(object): return self.docclass(*args)
TypeError: docclass() takes at most 4 arguments (5 given)

Python 3.2a4+ (py3k:86836, Nov 27 2010, 18:35:01) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
...     pass
... 
>>> class B:
...     attr = staticmethod(A)
... 
>>> help(B)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/milko/Среда/Python/py3k/Lib/site.py", line 447, in __call__
    return pydoc.help(*args, **kwds)
  File "/home/milko/Среда/Python/py3k/Lib/pydoc.py", line 1713, in __call__
    self.help(request)
  File "/home/milko/Среда/Python/py3k/Lib/pydoc.py", line 1760, in help
    else: doc(request, 'Help on %s:')
  File "/home/milko/Среда/Python/py3k/Lib/pydoc.py", line 1504, in doc
    pager(render_doc(thing, title, forceload))
  File "/home/milko/Среда/Python/py3k/Lib/pydoc.py", line 1499, in render_doc
    return title % desc + '\n\n' + text.document(object, name)
  File "/home/milko/Среда/Python/py3k/Lib/pydoc.py", line 319, in document
    if inspect.isclass(object): return self.docclass(*args)
  File "/home/milko/Среда/Python/py3k/Lib/pydoc.py", line 1214, in docclass
    lambda t: t[1] == 'static method')
  File "/home/milko/Среда/Python/py3k/Lib/pydoc.py", line 1159, in spill
    name, mod, object))
  File "/home/milko/Среда/Python/py3k/Lib/pydoc.py", line 319, in document
    if inspect.isclass(object): return self.docclass(*args)
TypeError: docclass() takes at most 4 positional arguments (5 given)
msg122536 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-11-27 18:11
Confirmed in py3k.
msg122538 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-11-27 18:27
The fix is simple:


--- Lib/pydoc.py	(revision 86824)
+++ Lib/pydoc.py	(working copy)
@@ -1110,7 +1110,7 @@
         result = result + self.section('FILE', file)
         return result
 
-    def docclass(self, object, name=None, mod=None):
+    def docclass(self, object, name=None, mod=None, *ignored):
         """Produce text documentation for a given class object."""
         realname = object.__name__
         name = name or realname

I think this is the right thing to do because HTMLDoc.docclass() has the following signature.


    def docclass(self, object, name=None, mod=None, funcs={}, classes={},
                 *ignored):
msg123221 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-12-03 09:59
Fixed in r86964.
History
Date User Action Args
2010-12-03 09:59:45georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg123221

resolution: fixed
2010-11-27 18:29:15eric.araujosetnosy: + ncoghlan, ron_adam, eric.araujo

versions: - Python 2.6
2010-11-27 18:27:43belopolskysetmessages: + msg122538
stage: needs patch -> test needed
2010-11-27 18:11:20belopolskysetnosy: + belopolsky
messages: + msg122536

assignee: belopolsky
type: behavior
stage: needs patch
2010-11-27 16:37:50milko.krachounovcreate