Skip to content

Commit

Permalink
fix braces for division hint
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberthirst committed Aug 2, 2024
1 parent 99304da commit 767f2da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ def has_folded_value(self):
"""
return "folded_value" in self._metadata

@property
def is_leaf(self):
return not self._children

def get_folded_value(self) -> "ExprNode":
"""
Attempt to get the folded value, bubbling up UnfoldableNode if the node
Expand Down
2 changes: 2 additions & 0 deletions vyper/ast/nodes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class VyperNode:
def has_folded_value(self): ...
@property
def parent(self): ...
@property
def is_leaf(self): ...
@classmethod
def get_fields(cls: Any) -> set: ...
def set_parent(self, parent: VyperNode) -> VyperNode: ...
Expand Down
8 changes: 6 additions & 2 deletions vyper/semantics/types/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,13 @@ def _add_div_hint(node, e):
else:
return e

def get_source(node):
source = node.node_source_code
return source if node.is_leaf else f"({source})"

if isinstance(node, vy_ast.BinOp):
e._hint = f"did you mean `{node.left.node_source_code} "
e._hint += f"{suggested} {node.right.node_source_code}`?"
e._hint = f"did you mean `{get_source(node.left)} "
e._hint += f"{suggested} {get_source(node.right)}`?"
elif isinstance(node, vy_ast.AugAssign):
e._hint = f"did you mean `{node.target.node_source_code} "
e._hint += f"{suggested}= {node.value.node_source_code}`?"
Expand Down

0 comments on commit 767f2da

Please sign in to comment.