[Numpy-discussion] Is this a small bug in numpydoc?

Fernando Perez fperez.net at gmail.com
Wed Apr 14 04:17:37 EDT 2010


Howdy,

in ipython we use numpydoc, and as I was just trying to build the docs
from a clean checkout of ipython's trunk, I kept getting errors that I
was able to fix with this patch:

amirbar[sphinxext]> svn diff
Index: numpydoc.py
===================================================================
--- numpydoc.py	(revision 8332)
+++ numpydoc.py	(working copy)
@@ -73,7 +73,8 @@
 def mangle_signature(app, what, name, obj, options, sig, retann):
     # Do not try to inspect classes that don't define `__init__`
     if (inspect.isclass(obj) and
-        'initializes x; see ' in pydoc.getdoc(obj.__init__)):
+        (not hasattr(obj, '__init__') or
+        'initializes x; see ' in pydoc.getdoc(obj.__init__))):
         return '', ''

     if not (callable(obj) or hasattr(obj, '__argspec_is_invalid_')): return


The errors were always of the type:

Exception occurred:
  File "/home/fperez/ipython/repo/trunk-lp/docs/sphinxext/numpydoc.py",
line 71, in mangle_signature
    'initializes x; see ' in pydoc.getdoc(obj.__init__)):
AttributeError: class Bunch has no attribute '__init__'
The full traceback has been saved in /tmp/sphinx-err-H1VlaY.log, if
you want to report the issue to the developers.

so it seems indeed that accessing __init__ without checking it's there
isn't a very good idea.

But I didn't write numpydoc and I'm tired, so I don't want to commit
this without a second pair of eyes...

Cheers,

f



More information about the NumPy-Discussion mailing list