From ecde72bb22ccedb36aa847dd50504c63ad04498c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 2 Jan 2020 22:05:10 +0100 Subject: [PATCH] fix: Fix getting annotation from nodes --- src/mkdocstrings/documenter.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mkdocstrings/documenter.py b/src/mkdocstrings/documenter.py index 728fed0e..fc7adf3c 100644 --- a/src/mkdocstrings/documenter.py +++ b/src/mkdocstrings/documenter.py @@ -445,14 +445,20 @@ def node_to_names(node: ast.Assign) -> dict: def node_to_annotated_names(node: ast.AnnAssign) -> dict: - name = node.target.attr + try: + name = node.target.id + except AttributeError: + name = node.target.attr lineno = node.lineno return {"names": [name], "lineno": lineno, "signature": node_to_annotation(node)} def node_to_annotation(node) -> str: if isinstance(node, ast.AnnAssign): - annotation = node.annotation.value.id + try: + annotation = node.annotation.id + except AttributeError: + annotation = node.annotation.value.id if hasattr(node.annotation, "slice"): annotation += f"[{node_to_annotation(node.annotation.slice.value)}]" return annotation