Skip to content

Commit

Permalink
fix: Fix getting annotation from nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jan 2, 2020
1 parent 2226e2d commit ecde72b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mkdocstrings/documenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ecde72b

Please sign in to comment.