Skip to content

Commit

Permalink
Merge branch 'master' into fix/nonreentrant-uses
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper authored May 7, 2024
2 parents abd0396 + 6d4c09c commit cffa731
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
4 changes: 2 additions & 2 deletions tests/unit/ast/test_annotate_and_optimize_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ def test_it_rewrites_unary_subtractions():
function_def = contract_ast.body[2]
return_stmt = function_def.body[0]

assert isinstance(return_stmt.value, python_ast.Num)
assert return_stmt.value.n == -1
assert isinstance(return_stmt.value, python_ast.Constant)
assert return_stmt.value.value == -1
10 changes: 0 additions & 10 deletions vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,6 @@ class Num(Constant):
# inherited class for all numeric constant node types
__slots__ = ()

@property
def n(self):
# TODO phase out use of Num.n and remove this
return self.value

def validate(self):
if self.value < SizeLimits.MIN_INT256:
raise OverflowException("Value is below lower bound for all numeric types", self)
Expand Down Expand Up @@ -894,11 +889,6 @@ def validate(self):
if ord(c) >= 256:
raise InvalidLiteral(f"'{c}' is not an allowed string literal character", self)

@property
def s(self):
# TODO phase out use of Str.s and remove this
return self.value


class Bytes(Constant):
__slots__ = ()
Expand Down
14 changes: 7 additions & 7 deletions vyper/ast/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ def _visit_docstring(self, node):

if node.body:
n = node.body[0]
if isinstance(n, python_ast.Expr) and isinstance(n.value, python_ast.Str):
if (
isinstance(n, python_ast.Expr)
and isinstance(n.value, python_ast.Constant)
and isinstance(n.value.value, str)
):
self.generic_visit(n.value)
n.value.ast_type = "DocStr"
del node.body[0]
Expand Down Expand Up @@ -470,13 +474,9 @@ def visit_UnaryOp(self, node):
self.generic_visit(node)

is_sub = isinstance(node.op, python_ast.USub)
is_num = (
hasattr(node.operand, "n")
and not isinstance(node.operand.n, bool)
and isinstance(node.operand.n, (int, Decimal))
)
is_num = hasattr(node.operand, "value") and isinstance(node.operand.value, (int, Decimal))
if is_sub and is_num:
node.operand.n = 0 - node.operand.n
node.operand.value = 0 - node.operand.value
node.operand.col_offset = node.col_offset
node.operand.node_source_code = node.node_source_code
return node.operand
Expand Down
8 changes: 4 additions & 4 deletions vyper/codegen/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, node, context, is_stmt=False):

def parse_Int(self):
typ = self.expr._metadata["type"]
return IRnode.from_list(self.expr.n, typ=typ)
return IRnode.from_list(self.expr.value, typ=typ)

def parse_Decimal(self):
val = self.expr.value * DECIMAL_DIVISOR
Expand Down Expand Up @@ -133,8 +133,8 @@ def parse_Str(self):

# Byte literals
def parse_Bytes(self):
bytez = self.expr.s
bytez_length = len(self.expr.s)
bytez = self.expr.value
bytez_length = len(self.expr.value)
typ = BytesT(bytez_length)
return self._make_bytelike(typ, bytez, bytez_length)

Expand Down Expand Up @@ -345,7 +345,7 @@ def parse_Subscript(self):
elif is_tuple_like(sub.typ):
# should we annotate expr.slice in the frontend with the
# folded value instead of calling reduced() here?
index = self.expr.slice.reduced().n
index = self.expr.slice.reduced().value
# note: this check should also happen in get_element_ptr
if not 0 <= index < len(sub.typ.member_types):
raise TypeCheckFailure("unreachable")
Expand Down

0 comments on commit cffa731

Please sign in to comment.