Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore[ux]: remove deprecated python AST classes #3998

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = (
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
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
Loading