Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Nov 10, 2023
1 parent f2afc0d commit 7f75749
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion vyper/ast/expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 3 additions & 6 deletions vyper/ast/folding.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions vyper/builtins/_signatures.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 3 additions & 1 deletion vyper/codegen/function_definitions/external_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, [], [])
Expand Down
8 changes: 4 additions & 4 deletions vyper/semantics/analysis/pre_typecheck.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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)


Expand All @@ -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

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion vyper/semantics/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion vyper/semantics/types/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down

0 comments on commit 7f75749

Please sign in to comment.