def _get_target(self, target): # Check if we are doing assignment of an iteration loop. if isinstance(target, vy_ast.Subscript) and self.context.in_for_loop: raise_exception = False if isinstance(target.value, vy_ast.Attribute): if f"{target.value.value.id}.{target.value.attr}" in self.context.in_for_loop: raise_exception = True if target.get("value.id") in self.context.in_for_loop: raise_exception = True if raise_exception: raise TypeCheckFailure("Failed for-loop constancy check") if isinstance(target, vy_ast.Name) and target.id in self.context.forvars: raise TypeCheckFailure("Failed for-loop constancy check") if isinstance(target, vy_ast.Tuple): target = Expr(target, self.context).lll_node for node in target.args: if (node.location == "storage" and self.context.is_constant()) or not node.mutable: raise TypeCheckFailure("Failed for-loop constancy check") return target target = Expr.parse_variable_location(target, self.context) if (target.location == "storage" and self.context.is_constant()) or not target.mutable: raise TypeCheckFailure("Failed for-loop constancy check") return target
def get_target(self, target): # Check if we are doing assignment of an iteration loop. if isinstance(target, ast.Subscript) and self.context.in_for_loop: raise_exception = False if isinstance(target.value, ast.Attribute): list_name = f"{target.value.value.id}.{target.value.attr}" if list_name in self.context.in_for_loop: raise_exception = True if isinstance(target.value, ast.Name) and \ target.value.id in self.context.in_for_loop: list_name = target.value.id raise_exception = True if raise_exception: raise StructureException( f"Altering list '{list_name}' which is being iterated!", self.stmt, ) if isinstance(target, ast.Name) and target.id in self.context.forvars: raise StructureException( f"Altering iterator '{target.id}' which is in use!", self.stmt, ) if isinstance(target, ast.Tuple): target = Expr(target, self.context).lll_node for node in target.args: constancy_checks(node, self.context, self.stmt) return target target = Expr.parse_variable_location(target, self.context) constancy_checks(target, self.context, self.stmt) return target
def get_target(self, target): if isinstance(target, ast.Subscript) and self.context.in_for_loop: # Check if we are doing assignment of an iteration loop. raise_exception = False if isinstance(target.value, ast.Attribute): list_name = "%s.%s" % (target.value.value.id, target.value.attr) if list_name in self.context.in_for_loop: raise_exception = True if isinstance(target.value, ast.Name) and \ target.value.id in self.context.in_for_loop: list_name = target.value.id raise_exception = True if raise_exception: raise StructureException("Altering list '%s' which is being iterated!" % list_name, self.stmt) if isinstance(target, ast.Name) and target.id in self.context.forvars: raise StructureException("Altering iterator '%s' which is in use!" % target.id, self.stmt) if isinstance(target, ast.Tuple): return Expr(target, self.context).lll_node target = Expr.parse_variable_location(target, self.context) if target.location == 'storage' and self.context.is_constant: raise ConstancyViolationException("Cannot modify storage inside a constant function: %s" % target.annotation) if not target.mutable: raise ConstancyViolationException("Cannot modify function argument: %s" % target.annotation) return target
def _get_target(self, target): if isinstance(target, vy_ast.Name) and target.id in self.context.forvars: raise TypeCheckFailure("Failed for-loop constancy check") if isinstance(target, vy_ast.Tuple): target = Expr(target, self.context).lll_node for node in target.args: if (node.location == "storage" and self.context.is_constant()) or not node.mutable: raise TypeCheckFailure("Failed for-loop constancy check") return target target = Expr.parse_variable_location(target, self.context) if (target.location == "storage" and self.context.is_constant()) or not target.mutable: raise TypeCheckFailure("Failed for-loop constancy check") return target
def get_target(self, target): # Check if we are doing assignment of an iteration loop. if isinstance(target, ast.Subscript) and self.context.in_for_loop: raise_exception = False if isinstance(target.value, ast.Attribute): list_name = f"{target.value.value.id}.{target.value.attr}" if list_name in self.context.in_for_loop: raise_exception = True if isinstance(target.value, ast.Name) and \ target.value.id in self.context.in_for_loop: list_name = target.value.id raise_exception = True if raise_exception: raise StructureException( f"Altering list '{list_name}' which is being iterated!", self.stmt, ) if isinstance(target, ast.Name) and target.id in self.context.forvars: raise StructureException( f"Altering iterator '{target.id}' which is in use!", self.stmt, ) if isinstance(target, ast.Tuple): return Expr(target, self.context).lll_node target = Expr.parse_variable_location(target, self.context) if target.location == 'storage' and self.context.is_constant(): raise ConstancyViolationException( f"Cannot modify storage inside {self.context.pp_constancy()}: {target.annotation}", self.stmt, ) if not target.mutable: raise ConstancyViolationException( f"Cannot modify function argument: {target.annotation}", self.stmt, ) return target