Skip to content

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

@yhtang

Description

@yhtang

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):

  • pytkdocs version [e.g. 0.2.1]: pytkdocs==0.12.0
  • Python version: [e.g. 3.8]: Python 3.8.12 (default, Aug 30 2021, 00:00:00) [GCC 10.3.1 20210422 (Red Hat 10.3.1-1)] on linux
  • OS: Fedora 33 5.14.18-100.fc33.x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions