Skip to content

Commit

Permalink
fix: Support USub and UAdd nodes in annotations
Browse files Browse the repository at this point in the history
Issue #71: #71
  • Loading branch information
pawamoy committed May 26, 2022
1 parent 0e692de commit 1169c51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/griffe/agents/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ def _get_unaryop_annotation(node: NodeUnaryOp, parent: Module | Class) -> Expres
return Expression(_get_annotation(node.op, parent), _get_annotation(node.operand, parent))


def _get_uadd_annotation(node: NodeUAdd, parent: Module | Class) -> str:
return "+"


def _get_usub_annotation(node: NodeUSub, parent: Module | Class) -> str:
return "-"


_node_annotation_map: dict[Type, Callable[[Any, Module | Class], str | Name | Expression]] = {
NodeAttribute: _get_attribute_annotation,
NodeBinOp: _get_binop_annotation,
Expand All @@ -704,6 +712,8 @@ def _get_unaryop_annotation(node: NodeUnaryOp, parent: Module | Class) -> Expres
NodeSubscript: _get_subscript_annotation,
NodeTuple: _get_tuple_annotation,
NodeUnaryOp: _get_unaryop_annotation,
NodeUAdd: _get_uadd_annotation,
NodeUSub: _get_usub_annotation,
}

# TODO: remove once Python 3.8 support is dropped
Expand Down
1 change: 1 addition & 0 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_relative_to_absolute_imports(code, path, is_package, expected):
"A | B",
"A[[B, C], D]",
"A(b=c, d=1)",
"A[-1, +2.3]",
],
)
def test_building_annotations_from_nodes(expression):
Expand Down

0 comments on commit 1169c51

Please sign in to comment.