Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yhtang opened this issue Dec 14, 2021 · 0 comments
Open

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

yhtang opened this issue Dec 14, 2021 · 0 comments

Comments

@yhtang
Copy link

yhtang commented Dec 14, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant