From 16b069cf548f09186a71cb9ce8cfb31956435219 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:13:54 +0800 Subject: [PATCH] rename to VariableConstancy --- vyper/semantics/analysis/base.py | 8 ++++---- vyper/semantics/analysis/local.py | 6 +++--- vyper/semantics/analysis/module.py | 8 ++++---- vyper/semantics/analysis/utils.py | 8 ++++---- vyper/semantics/environment.py | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/vyper/semantics/analysis/base.py b/vyper/semantics/analysis/base.py index bd49eadc7a..3cd346e532 100644 --- a/vyper/semantics/analysis/base.py +++ b/vyper/semantics/analysis/base.py @@ -93,7 +93,7 @@ def from_abi(cls, abi_dict: Dict) -> "StateMutability": # specifying a state mutability modifier at all. Do the same here. -class Constancy(_StringEnum): +class VariableConstancy(_StringEnum): MUTABLE = _StringEnum.auto() RUNTIME_CONSTANT = _StringEnum.auto() COMPILE_TIME_CONSTANT = _StringEnum.auto() @@ -165,7 +165,7 @@ class VarInfo: typ: VyperType location: DataLocation = DataLocation.UNSET - constancy: Constancy = Constancy.MUTABLE + constancy: VariableConstancy = VariableConstancy.MUTABLE is_public: bool = False is_immutable: bool = False is_transient: bool = False @@ -198,7 +198,7 @@ class ExprInfo: typ: VyperType var_info: Optional[VarInfo] = None location: DataLocation = DataLocation.UNSET - constancy: Constancy = Constancy.MUTABLE + constancy: VariableConstancy = VariableConstancy.MUTABLE is_immutable: bool = False def __post_init__(self): @@ -246,7 +246,7 @@ def validate_modification(self, node: vy_ast.VyperNode, mutability: StateMutabil if self.location == DataLocation.CALLDATA: raise ImmutableViolation("Cannot write to calldata", node) - if self.constancy == Constancy.COMPILE_TIME_CONSTANT: + if self.constancy == VariableConstancy.COMPILE_TIME_CONSTANT: raise ImmutableViolation("Constant value cannot be written to", node) if self.is_immutable: if node.get_ancestor(vy_ast.FunctionDef).get("name") != "__init__": diff --git a/vyper/semantics/analysis/local.py b/vyper/semantics/analysis/local.py index ebf5ff99ba..c3c4bc4fce 100644 --- a/vyper/semantics/analysis/local.py +++ b/vyper/semantics/analysis/local.py @@ -19,7 +19,7 @@ VariableDeclarationException, VyperException, ) -from vyper.semantics.analysis.base import Constancy, VarInfo +from vyper.semantics.analysis.base import VariableConstancy, VarInfo from vyper.semantics.analysis.common import VyperNodeVisitorBase from vyper.semantics.analysis.utils import ( get_common_types, @@ -197,7 +197,7 @@ def __init__( arg.typ, location=location, is_immutable=is_immutable, - constancy=Constancy.RUNTIME_CONSTANT, + constancy=VariableConstancy.RUNTIME_CONSTANT, ) for node in fn_node.body: @@ -484,7 +484,7 @@ def visit_For(self, node): with self.namespace.enter_scope(): try: self.namespace[iter_name] = VarInfo( - possible_target_type, constancy=Constancy.COMPILE_TIME_CONSTANT + possible_target_type, constancy=VariableConstancy.COMPILE_TIME_CONSTANT ) except VyperException as exc: raise exc.with_annotation(node) from None diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index c9daa0f807..120739a89d 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -18,7 +18,7 @@ VariableDeclarationException, VyperException, ) -from vyper.semantics.analysis.base import Constancy, VarInfo +from vyper.semantics.analysis.base import VariableConstancy, VarInfo from vyper.semantics.analysis.common import VyperNodeVisitorBase from vyper.semantics.analysis.local import ExprVisitor from vyper.semantics.analysis.utils import check_constant, validate_expected_type @@ -187,11 +187,11 @@ def visit_VariableDecl(self, node): ) constancy = ( - Constancy.RUNTIME_CONSTANT + VariableConstancy.RUNTIME_CONSTANT if node.is_immutable - else Constancy.COMPILE_TIME_CONSTANT + else VariableConstancy.COMPILE_TIME_CONSTANT if node.is_constant - else Constancy.MUTABLE + else VariableConstancy.MUTABLE ) type_ = type_from_annotation(node.annotation, data_loc) diff --git a/vyper/semantics/analysis/utils.py b/vyper/semantics/analysis/utils.py index 8ffe0df454..49cf37c22f 100644 --- a/vyper/semantics/analysis/utils.py +++ b/vyper/semantics/analysis/utils.py @@ -17,7 +17,7 @@ ZeroDivisionException, ) from vyper.semantics import types -from vyper.semantics.analysis.base import Constancy, ExprInfo, VarInfo +from vyper.semantics.analysis.base import VariableConstancy, ExprInfo, VarInfo from vyper.semantics.analysis.levenshtein_utils import get_levenshtein_error_suggestions from vyper.semantics.namespace import get_namespace from vyper.semantics.types.base import TYPE_T, VyperType @@ -198,7 +198,7 @@ def _raise_invalid_reference(name, node): if isinstance(s, VyperType): # ex. foo.bar(). bar() is a ContractFunctionT return [s] - if is_self_reference and s.constancy >= Constancy.RUNTIME_CONSTANT: + if is_self_reference and s.constancy >= VariableConstancy.RUNTIME_CONSTANT: _raise_invalid_reference(name, node) # general case. s is a VarInfo, e.g. self.foo return [s.typ] @@ -647,7 +647,7 @@ def check_kwargable(node: vy_ast.VyperNode) -> bool: return True value_type = get_expr_info(node) - return value_type.constancy >= Constancy.RUNTIME_CONSTANT + return value_type.constancy >= VariableConstancy.RUNTIME_CONSTANT def _check_literal(node: vy_ast.VyperNode) -> bool: @@ -690,4 +690,4 @@ def check_constant(node: vy_ast.VyperNode) -> bool: return True value_type = get_expr_info(node) - return value_type.constancy == Constancy.COMPILE_TIME_CONSTANT + return value_type.constancy == VariableConstancy.COMPILE_TIME_CONSTANT diff --git a/vyper/semantics/environment.py b/vyper/semantics/environment.py index 09006effa6..937237ad0b 100644 --- a/vyper/semantics/environment.py +++ b/vyper/semantics/environment.py @@ -1,6 +1,6 @@ from typing import Dict -from vyper.semantics.analysis.base import Constancy, VarInfo +from vyper.semantics.analysis.base import VariableConstancy, VarInfo from vyper.semantics.types import AddressT, BytesT, VyperType from vyper.semantics.types.shortcuts import BYTES32_T, UINT256_T @@ -52,7 +52,7 @@ def get_constant_vars() -> Dict: """ result = {} for k, v in CONSTANT_ENVIRONMENT_VARS.items(): - result[k] = VarInfo(v, constancy=Constancy.RUNTIME_CONSTANT) + result[k] = VarInfo(v, constancy=VariableConstancy.RUNTIME_CONSTANT) return result