def from_annotation( cls, node: Union[vy_ast.Name, vy_ast.Call], location: DataLocation = DataLocation.UNSET, is_immutable: bool = False, is_public: bool = False, ) -> "BaseTypeDefinition": """ Generate a `BaseTypeDefinition` instance of this type from `AnnAssign.annotation` Arguments --------- node : VyperNode Vyper ast node from the `annotation` member of an `AnnAssign` node. Returns ------- BaseTypeDefinition BaseTypeDefinition related to the primitive that the method was called on. """ if not isinstance(node, vy_ast.Name): raise StructureException("Invalid type assignment", node) if node.id != cls._id: raise UnexpectedValue("Node id does not match type name") return cls._type(location, is_immutable, is_public)
def from_annotation( cls, node: vy_ast.VyperNode, location: DataLocation = DataLocation.MEMORY, is_immutable: bool = False, is_public: bool = False, ) -> _ArrayValueDefinition: if not isinstance(node, vy_ast.Subscript): raise StructureException( f"Cannot declare {cls._id} type without a maximum length", node ) if len(node.get_descendants(vy_ast.Subscript, include_self=True)) > 1: raise StructureException(f"Multidimensional {cls._id} arrays are not supported", node) if node.get("value.id") != cls._id: raise UnexpectedValue("Node id does not match type name") length = validation.utils.get_index_value(node.slice) # type: ignore return cls._type(length, location, is_immutable, is_public)