Type System

The type system defines all available types in Viper. Type is the base class with static accessors for primitive types.

When to use: Use types to define schemas, validate data, and create parameterized containers like vectors and maps.

Quick Start

from dsviper import Type, TypeVector, TypeMap, TypeOptional

# Primitive type constants
t_int = Type.INT64
t_str = Type.STRING

# Parameterized container types
t_vec = TypeVector(Type.STRING)           # list of strings
t_map = TypeMap(Type.STRING, Type.INT64)  # dict[str, int]

# Nested types
t_nested = TypeMap(Type.STRING, TypeVector(Type.FLOAT))

# Nullable type
t_opt = TypeOptional(Type.STRING)

Choosing the Right Type

Use Case

Type Class

Example

Primitive value

Type.STRING, Type.INT64

Built-in constants

Homogeneous list

TypeVector

TypeVector(Type.INT64)

Key-value mapping

TypeMap

TypeMap(Type.STRING, Type.INT64)

Nullable value

TypeOptional

TypeOptional(Type.STRING)

Concurrent list

TypeXArray

TypeXArray(Type.STRING)

Fixed-size tuple

TypeTuple

TypeTuple([Type.INT64, Type.STRING])

Base Class

dsviper.Type

A utility class to handle type representation.

dsviper.TypeName

A class used to describe the name of a type.

Primitive Types

dsviper.TypeVoid

A class used to represent the void type.

dsviper.TypeBool

A class used to represent the bool type.

dsviper.TypeUInt8

A class used to represent the uint8 type.

dsviper.TypeUInt16

A class used to represent the uint16 type.

dsviper.TypeUInt32

A class used to represent the uint32 type.

dsviper.TypeUInt64

A class used to represent the uint64 type.

dsviper.TypeInt8

A class used to represent the int8 type.

dsviper.TypeInt16

A class used to represent the int16 type.

dsviper.TypeInt32

A class used to represent the int32 type.

dsviper.TypeInt64

A class used to represent the int64 type.

dsviper.TypeFloat

A class used to represent the float type.

dsviper.TypeDouble

A class used to represent the double type.

dsviper.TypeString

A class used to represent the string type.

dsviper.TypeBlob

A class used to represent the blob type.

dsviper.TypeBlobId

A class used to represent the blob_id type.

dsviper.TypeCommitId

A class used to represent the commit_id type.

dsviper.TypeUUId

A class used to represent the uuid type.

Container Types

dsviper.TypeVector

A class used to represent a vector<element_type> type.

dsviper.TypeSet

A class used to represent a set<element_type> type.

dsviper.TypeMap

A class used to represent a map<element_type> type.

dsviper.TypeXArray

A class used to represent a xarray<element_type> type.

dsviper.TypeOptional

A class used to represent an optional<element_type> type.

Algebraic Types

dsviper.TypeTuple

A class used to represent a tuple<T0, ...> type.

dsviper.TypeVec

A class used to represent a vec<element_type, size> type.

dsviper.TypeMat

A class used to represent a mat<numeric_type, columns, rows> type.

dsviper.TypeVariant

A class used to represent a variant<T0, ...> type.

dsviper.TypeAny

A class used to represent the any type.

User-Defined Types

dsviper.TypeStructure

A class used to represent a struct type.

dsviper.TypeStructureDescriptor

A class used to describe the fields of a struct.

dsviper.TypeStructureField

A class used to represent a field for a struct.

dsviper.TypeEnumeration

A class used to represent an enum type.

dsviper.TypeEnumerationCase

A class used to represent a case for an enum type.

dsviper.TypeEnumerationDescriptor

A class used to describe the cases of an enum.

Concept Types

dsviper.TypeConcept

A class used to represent a concept type.

dsviper.TypeClub

A class used to represent a club type.

dsviper.TypeKey

A class used to represent a key<element_type> type where element_type is a concept, club or any_concept.

dsviper.TypeAnyConcept

A class used to represent the any_concept type.