Skip to content

Commit

Permalink
chore[ux]: remove deprecated python AST classes (#3998)
Browse files Browse the repository at this point in the history
remove references to python AST classes which trigger deprecation
warnings in python 3.12

---------

Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
  • Loading branch information
tserg and charles-cooper committed May 7, 2024
1 parent 5739624 commit ef2d535
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 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
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

0 comments on commit ef2d535

Please sign in to comment.