From 04db59069515e8aac8bb9cf4459376fcbc338834 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Fri, 3 May 2024 18:02:25 +0800 Subject: [PATCH 1/3] fix docstring check --- vyper/ast/parse.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vyper/ast/parse.py b/vyper/ast/parse.py index 690f88d3b5..3aaa2879e1 100644 --- a/vyper/ast/parse.py +++ b/vyper/ast/parse.py @@ -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] From 8b3c5d1db6aa62629e66a0c195ffb4e67bb66217 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Fri, 3 May 2024 20:08:07 +0800 Subject: [PATCH 2/3] more fixes --- tests/unit/ast/test_annotate_and_optimize_ast.py | 4 ++-- vyper/ast/parse.py | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/unit/ast/test_annotate_and_optimize_ast.py b/tests/unit/ast/test_annotate_and_optimize_ast.py index b202f6d8a3..7e1641e49e 100644 --- a/tests/unit/ast/test_annotate_and_optimize_ast.py +++ b/tests/unit/ast/test_annotate_and_optimize_ast.py @@ -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 diff --git a/vyper/ast/parse.py b/vyper/ast/parse.py index 3aaa2879e1..713be6c913 100644 --- a/vyper/ast/parse.py +++ b/vyper/ast/parse.py @@ -474,13 +474,11 @@ 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 = isinstance(node.operand, python_ast.Constant) 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 From a0cd92f9a3d62e0ae5915003a88ae03142ea320e Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Sat, 4 May 2024 22:33:22 +0800 Subject: [PATCH 3/3] apply bts suggestion --- vyper/ast/parse.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vyper/ast/parse.py b/vyper/ast/parse.py index 713be6c913..d4569dd644 100644 --- a/vyper/ast/parse.py +++ b/vyper/ast/parse.py @@ -474,9 +474,7 @@ def visit_UnaryOp(self, node): self.generic_visit(node) is_sub = isinstance(node.op, python_ast.USub) - is_num = isinstance(node.operand, python_ast.Constant) and isinstance( - node.operand.value, (int, Decimal) - ) + is_num = hasattr(node.operand, "value") and isinstance(node.operand.value, (int, Decimal)) if is_sub and is_num: node.operand.value = 0 - node.operand.value node.operand.col_offset = node.col_offset