mkdocstrings / pytkdocs

Load Python objects documentation.
https://mkdocstrings.github.io/pytkdocs
ISC License
50 stars 32 forks source link

[BUG] Cannot extract docstring from output of `make_dataclass` #125

Open yhtang opened 2 years ago

yhtang commented 2 years ago

Describe the bug If a data class is created using the function dataclasses.make_dataclass instead of the @dataclasses.dataclass decorator, then the docstring (and even the entire node attribute data) is empty.

To Reproduce Applying mkdocstrings to the following file

from dataclasses import make_dataclass

f = make_dataclass('f', ['x'])

leads to the error

ERROR    -  mkdocstrings.extension: 'docstring'
Traceback (most recent call last):
  File ".../lib/python3.8/site-packages/pytkdocs/cli.py", line 205, in main
    output = json.dumps(process_json(line))
  File ".../lib/python3.8/site-packages/pytkdocs/cli.py", line 114, in process_json
    return process_config(json.loads(json_input))
  File ".../lib/python3.8/site-packages/pytkdocs/cli.py", line 91, in process_config
    obj = loader.get_object_documentation(path, members)
  File ".../lib/python3.8/site-packages/pytkdocs/loader.py", line 360, in get_object_documentation
    root_object = self.get_class_documentation(leaf, members)
  File ".../lib/python3.8/site-packages/pytkdocs/loader.py", line 531, in get_class_documentation
    self.add_fields(
  File ".../lib/python3.8/site-packages/pytkdocs/loader.py", line 599, in add_fields
    root_object.add_child(add_method(child_node))
  File ".../lib/python3.8/site-packages/pytkdocs/loader.py", line 802, in get_annotated_dataclass_field
    docstring=attribute_data["docstring"],
KeyError: 'docstring'

Expected behavior The result should be equivalent to what can be extracted from

@dataclass
class f:
    x: int

Screenshots If you are using pytkdocs through mkdocstrings: yes If relevant, please attach a screenshot: see the code block from the 'reproduction' section above.

System (please complete the following information):