keras-team/keras-autodoc

Support for dataclasses

lgvaz opened this issue · 1 comments

lgvaz commented

When parsing a @dataclass, DocumentationGenerator.generate fails with AttributeError: module 'mantisshrimp.core.bbox' has no attribute '__create_fn__' (full stack trace at the bottom).

What happens is that the __init__ representation from dataclasses is different than for normal classes.

For normal classes we have:

<function DocumentationGenerator.__init__ at 0x104e56710>

While for dataclasses:

<function __create_fn__.<locals>.__init__ at 0x13b3c1290>

If I understood the problem correctly, get_class_from_method is trying to get the name of the class from the representation, but the name of the class is not present in the dataclass __init__.


Traceback (most recent call last):
  File "autogen.py", line 340, in <module>
    generate(mantisshrimp_dir / "docs" / "sources")
  File "autogen.py", line 256, in generate
    doc_generator.generate(dest_dir)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/autogen.py", line 82, in generate
    markdown_text += self._render(element)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/autogen.py", line 109, in _render
    return self._render_from_object(object_, signature_override)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/autogen.py", line 116, in _render_from_object
    object_, signature_override, self.max_signature_line_length
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/get_signatures.py", line 51, in get_signature
    return get_class_signature(object_, override, max_line_length)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/get_signatures.py", line 45, in get_class_signature
    signature_end = get_signature_end(cls.__init__)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/get_signatures.py", line 25, in get_signature_end
    if utils.ismethod(function):
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/utils.py", line 80, in ismethod
    return get_class_from_method(function) is not None
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/utils.py", line 73, in get_class_from_method
    meth.__qualname__.split('.<locals>', 1)[0].rsplit('.', 1)[0])

I see what you mean, the code to know if an object is a function or a method is quite brittle. Basically, if this check wasn't needed the problem would go away. I'm not sure what is the correct solution for this.