#102 failure on class with __getattr__

v3.0
closed-fixed
Edward Loper
inspection (59)
5
2006-08-21
2006-05-31
Daniel Nogradi
No

Epydoc 3.0alpha2 fails to produce documentation for the
following content:

---------------------------------------
class x:
def __getattr__( self, attr ):
return None

y = x( )
---------------------------------------

and the traceback is:

Traceback (most recent call last):
Progress:
00:00
File "/usr/bin/epydoc", line 7, in
?---------------------------------------------------------------------------------------------]
cli()
Building documentation: x

File
"/usr/lib/python2.3/site-packages/epydoc/cli.py", line
590, in cli
main(options, names)
File
"/usr/lib/python2.3/site-packages/epydoc/cli.py", line
429, in main
add_submodules=(options.action!='text'))
File
"/usr/lib/python2.3/site-packages/epydoc/docbuilder.py",
line 130, in build_doc_index
doc_pairs = _get_docs_from_items(items, introspect,
parse, add_submodules)
File
"/usr/lib/python2.3/site-packages/epydoc/docbuilder.py",
line 253, in _get_docs_from_items
doc_pairs.append(_get_docs_from_pyname(
File
"/usr/lib/python2.3/site-packages/epydoc/docbuilder.py",
line 308, in _get_docs_from_pyname
introspect_doc = introspect_docs(name=name)
File
"/usr/lib/python2.3/site-packages/epydoc/docintrospecter.py",
line 149, in introspect_docs
introspect_func(value, val_doc)
File
"/usr/lib/python2.3/site-packages/epydoc/docintrospecter.py",
line 281, in introspect_module
child_val_doc = introspect_docs(child,
context=module_doc)
File
"/usr/lib/python2.3/site-packages/epydoc/docintrospecter.py",
line 149, in introspect_docs
introspect_func(value, val_doc)
File
"/usr/lib/python2.3/site-packages/epydoc/docintrospecter.py",
line 369, in introspect_class
for base in cls.__bases__:
TypeError: iteration over non-sequence

Discussion

  • Logged In: NO

    The indentation got mixed up, but the error happens with
    correct indentation.

     
  • Edward Loper
    Edward Loper
    2006-08-21

    • status: open --> closed-fixed
     
  • Edward Loper
    Edward Loper
    2006-08-21

    Logged In: YES
    user_id=195958

    I would say that this is a bug in your code -- definining
    __getattr__ to indiscriminantly return values for all
    attributes (and esp __special__ attributes) is dangerous,
    as evidenced by the following:

    >>> y
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: 'NoneType' object is not callable

    (python finds that y.__str__ exists, since __getattr__
    returns it, but it's not usable!)

    That said, I do want epydoc to be robust, so I added a
    check to make sure __bases__ actually contains a list, and
    to issue a warning if it doesn't. This still means that
    in the code you gave, 'y' will be treated as a class --
    the stdlib module inspect returns True for isclass(y),
    since it defines __bases__ -- but at least epydoc
    shouldn't crash.

    Fixed in subversion revision 1265.

     
  • Edward Loper
    Edward Loper
    2006-09-04

    Logged In: YES
    user_id=195958

    Yep. This was fixed in subversion revision 1265, using
    the exact fix that was suggested in the python-list
    messages you referenced (i.e., defining my own isclass
    function that tests:

    isinstance(o, (types.TypeType, types.ClassType))

    So this problem should be resolved in epydoc 3.0 alpha 3.