diff --git a/vyper/ast/expansion.py b/vyper/ast/expansion.py index fe8f374123..5471b971a4 100644 --- a/vyper/ast/expansion.py +++ b/vyper/ast/expansion.py @@ -109,7 +109,7 @@ def remove_unused_statements(vyper_module: vy_ast.Module) -> None: # constant declarations - values were substituted within the AST during folding for node in vyper_module.get_children(vy_ast.VariableDecl, {"is_constant": True}): - vyper_module.remove_from_body(node) + vyper_module.remove_from_body(node) # `implements: interface` statements - validated during type checking for node in vyper_module.get_children(vy_ast.ImplementsDecl): diff --git a/vyper/ast/folding.py b/vyper/ast/folding.py index cc8e2dc4d1..1121903109 100644 --- a/vyper/ast/folding.py +++ b/vyper/ast/folding.py @@ -1,10 +1,9 @@ -from typing import Optional, Union +from typing import Union from vyper.ast import nodes as vy_ast from vyper.builtins.functions import DISPATCH_TABLE -from vyper.exceptions import UnfoldableNode, UnknownType +from vyper.exceptions import UnfoldableNode from vyper.semantics.types.base import VyperType -from vyper.semantics.types.utils import type_from_annotation def fold(vyper_module: vy_ast.Module) -> None: @@ -154,9 +153,7 @@ def replace_user_defined_constants(vyper_module: vy_ast.Module) -> int: # Extract type definition from propagated annotation type_ = node._metadata["type"] - changed_nodes += replace_constant( - vyper_module, node.target.id, node.value, type_, False - ) + changed_nodes += replace_constant(vyper_module, node.target.id, node.value, type_, False) return changed_nodes diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index 1c27103ca7..ca0c986fe0 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -916,7 +916,7 @@ def prefold(self) -> ExprNode: operand = self.operand._metadata.get("folded_value") if operand is None: return - + value = self.op._op(operand.value) return type(self.operand).from_node(self, value=value) diff --git a/vyper/builtins/_signatures.py b/vyper/builtins/_signatures.py index 765789f0ec..332094cc0f 100644 --- a/vyper/builtins/_signatures.py +++ b/vyper/builtins/_signatures.py @@ -1,12 +1,15 @@ import functools from typing import Dict -from vyper.ast import nodes as vy_ast from vyper.ast.validation import validate_call_args from vyper.codegen.expr import Expr from vyper.codegen.ir_node import IRnode from vyper.exceptions import CompilerPanic, TypeMismatch -from vyper.semantics.analysis.utils import check_constant, get_exact_type_from_node, validate_expected_type +from vyper.semantics.analysis.utils import ( + check_constant, + get_exact_type_from_node, + validate_expected_type, +) from vyper.semantics.types import TYPE_T, KwargSettings, VyperType from vyper.semantics.types.utils import type_from_annotation diff --git a/vyper/codegen/function_definitions/external_function.py b/vyper/codegen/function_definitions/external_function.py index ee91ec754d..bd409012dc 100644 --- a/vyper/codegen/function_definitions/external_function.py +++ b/vyper/codegen/function_definitions/external_function.py @@ -130,7 +130,9 @@ def handler_for(calldata_kwargs, folded_default_kwargs, original_default_kwargs) # unfolded ast folded_default_kwargs = folded_keyword_args[1:] - sig, calldata_min_size, ir_node = handler_for(calldata_kwargs, folded_default_kwargs, original_default_kwargs) + sig, calldata_min_size, ir_node = handler_for( + calldata_kwargs, folded_default_kwargs, original_default_kwargs + ) ret[sig] = calldata_min_size, ir_node sig, calldata_min_size, ir_node = handler_for(keyword_args, [], []) diff --git a/vyper/semantics/analysis/pre_typecheck.py b/vyper/semantics/analysis/pre_typecheck.py index 7d77fc096b..d175604e3f 100644 --- a/vyper/semantics/analysis/pre_typecheck.py +++ b/vyper/semantics/analysis/pre_typecheck.py @@ -1,6 +1,5 @@ from vyper import ast as vy_ast from vyper.exceptions import UnfoldableNode -from vyper.semantics.analysis.common import VyperNodeVisitorBase def get_constants(node: vy_ast.Module) -> dict: @@ -39,11 +38,11 @@ def get_constants(node: vy_ast.Module) -> dict: def pre_typecheck(node: vy_ast.Module): constants = get_constants(node) - + for n in node.get_descendants(reverse=True): if isinstance(n, vy_ast.VariableDecl): continue - + prefold(n, constants) @@ -53,7 +52,7 @@ def prefold(node: vy_ast.VyperNode, constants: dict) -> None: if isinstance(node, vy_ast.UnaryOp): node._metadata["folded_value"] = node.prefold() - + if isinstance(node, (vy_ast.Constant, vy_ast.NameConstant)): node._metadata["folded_value"] = node @@ -71,6 +70,7 @@ def prefold(node: vy_ast.VyperNode, constants: dict) -> None: if isinstance(node, vy_ast.Call): if isinstance(node.func, vy_ast.Name): from vyper.builtins.functions import DISPATCH_TABLE + func_name = node.func.id call_type = DISPATCH_TABLE.get(func_name) diff --git a/vyper/semantics/analysis/utils.py b/vyper/semantics/analysis/utils.py index 76ca64b6e5..7d71c6c948 100644 --- a/vyper/semantics/analysis/utils.py +++ b/vyper/semantics/analysis/utils.py @@ -663,7 +663,7 @@ def check_constant(node: vy_ast.VyperNode) -> bool: if isinstance(node, vy_ast.BinOp): return all(check_kwargable(i) for i in (node.left, node.right)) - + if isinstance(node, vy_ast.BoolOp): return all(check_kwargable(i) for i in node.values) diff --git a/vyper/semantics/types/utils.py b/vyper/semantics/types/utils.py index 8a95a879d4..4a1dd98024 100644 --- a/vyper/semantics/types/utils.py +++ b/vyper/semantics/types/utils.py @@ -151,7 +151,11 @@ def get_index_value(node: vy_ast.Index) -> int: # TODO: revisit this! from vyper.semantics.analysis.utils import get_possible_types_from_node - value = node.value if isinstance(node.value, vy_ast.Int) else node.value._metadata.get("folded_value") + value = ( + node.value + if isinstance(node.value, vy_ast.Int) + else node.value._metadata.get("folded_value") + ) if not isinstance(value, vy_ast.Int): if hasattr(node, "value"): # even though the subscript is an invalid type, first check if it's a valid _something_