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] Dict[] type annotations make pytkdocs explode #73

Closed
nigelm opened this issue Oct 28, 2020 · 5 comments
Closed

[BUG] Dict[] type annotations make pytkdocs explode #73

nigelm opened this issue Oct 28, 2020 · 5 comments
Assignees
Labels
annotations Related to type annotations bug Something isn't working

Comments

@nigelm
Copy link

nigelm commented Oct 28, 2020

Describe the bug
If there is a type annotation of the form Dict[x, y] then the parser throws an exception.

To Reproduce

from typing import Any
from typing import Dict
...
my_thing: Dict[str, Any] = {}

Expected behavior
For it not to throw an exception like this:

INFO    -  Building documentation...
INFO    -  Cleaning site directory
ERROR   -  mkdocstrings.handlers.python: Collection failed: 'Tuple' object has no attribute 'value'
Traceback (most recent call last):
  File "/Users/nigel/Library/Caches/pypoetry/virtualenvs/python-broadworks-tools-zQ4enKcE-py3.9/src/pytkdocs/src/pytkdocs/cli.py", line 205, in main
    output = json.dumps(process_json(line))
  File "/Users/nigel/Library/Caches/pypoetry/virtualenvs/python-broadworks-tools-zQ4enKcE-py3.9/src/pytkdocs/src/pytkdocs/cli.py", line 114, in process_json
    return process_config(json.loads(json_input))
  File "/Users/nigel/Library/Caches/pypoetry/virtualenvs/python-broadworks-tools-zQ4enKcE-py3.9/src/pytkdocs/src/pytkdocs/cli.py", line 91, in process_config
    obj = loader.get_object_documentation(path, members)
  File "/Users/nigel/Library/Caches/pypoetry/virtualenvs/python-broadworks-tools-zQ4enKcE-py3.9/src/pytkdocs/src/pytkdocs/loader.py", line 342, in get_object_documentation
    root_object = self.get_module_documentation(leaf, members)
  File "/Users/nigel/Library/Caches/pypoetry/virtualenvs/python-broadworks-tools-zQ4enKcE-py3.9/src/pytkdocs/src/pytkdocs/loader.py", line 409, in get_module_documentation
    root_object.add_child(self.get_class_documentation(child_node))
  File "/Users/nigel/Library/Caches/pypoetry/virtualenvs/python-broadworks-tools-zQ4enKcE-py3.9/src/pytkdocs/src/pytkdocs/loader.py", line 444, in get_class_documentation
    attributes_data.update(get_instance_attributes(class_.__init__))
  File "/Users/nigel/Library/Caches/pypoetry/virtualenvs/python-broadworks-tools-zQ4enKcE-py3.9/src/pytkdocs/src/pytkdocs/parsers/attributes.py", line 155, in get_instance_attributes
    annotation = node_to_annotation(assignment)
  File "/Users/nigel/Library/Caches/pypoetry/virtualenvs/python-broadworks-tools-zQ4enKcE-py3.9/src/pytkdocs/src/pytkdocs/parsers/attributes.py", line 19, in node_to_annotation
    return f"{node.annotation.value.id}[{node_to_annotation(node.annotation.slice.value)}]"  # type: ignore
AttributeError: 'Tuple' object has no attribute 'value'

ERROR   -  mkdocstrings.extension: Could not collect 'python_broadworks_tools.enterprise'
ERROR   -  Error reading page 'api/enterprise.md': 'Tuple' object has no attribute 'value'

System (please complete the following information):

  • pytkdocs version 0.9.0 and github version
  • Python version: 3.8.5
  • OS: Mac
@pawamoy
Copy link
Member

pawamoy commented Nov 3, 2020

Hello, thank you for the report!

I'll try to replicate first, then look for a fix (PRs welcome!) 🙂

@pawamoy pawamoy added annotations Related to type annotations attributes unconfirmed This bug was not reproduced yet and removed attributes labels Nov 3, 2020
@pawamoy pawamoy self-assigned this Nov 3, 2020
@phil65
Copy link

phil65 commented Dec 8, 2020

This only seems to happen on Python 3.9.x. (The bug report mentions the wrong version)

@pawamoy
Copy link
Member

pawamoy commented Dec 8, 2020

Thanks @phil65 for the note. It must then be related to #75: ast has changed in Python 3.9, and it breaks the current pytkdocs parser. These bugs are preventing the use of Python 3.9 so I'll mark this (in my head) as pretty urgent.

@pawamoy
Copy link
Member

pawamoy commented Dec 8, 2020

I've pushed a fix, could you try again with the latest commit @nigelm, @phil65?

pawamoy added a commit that referenced this issue Dec 8, 2020
It seems `ast` has changed in Python 3.9.
Some objects who previously had a `value` attribute
don't have it anymore.

Issue #73: #73
Issue #75: #75
@pawamoy pawamoy added bug Something isn't working and removed unconfirmed This bug was not reproduced yet labels Dec 8, 2020
@pawamoy
Copy link
Member

pawamoy commented Jan 3, 2021

Should be fixed in 0.10.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annotations Related to type annotations bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants