Annotation Type Hints#

colour.hints

Any(*args, **kwargs)

Special type indicating an unconstrained type.

Callable

Callable type; Callable[[int], str] is a function of (int) -> str.

Dict

A generic version of dict.

Generator

A generic version of collections.abc.Generator.

Iterable

A generic version of collections.abc.Iterable.

Iterator

A generic version of collections.abc.Iterator.

List

A generic version of list.

Mapping

A generic version of collections.abc.Mapping.

ModuleType

alias of module

Optional

Optional type.

Union

Union type; Union[X, Y] means either X or Y.

Sequence

A generic version of collections.abc.Sequence.

SupportsIndex(*args, **kwargs)

An ABC with one abstract method __index__.

TextIO()

Typed version of the return of open() in text mode.

Tuple

Tuple type; Tuple[X, Y] is the cross-product type of X and Y.

Type

A special construct usable to annotate class objects.

TypedDict(typename[, fields, total])

A simple typed namespace.

TypeVar(name, *constraints[, bound, ...])

Type variable.

RegexFlag

NewType creates simple unique types with almost zero runtime overhead. NewType(name, tp) is considered a subtype of tp by static type checkers. At runtime, NewType(name, tp) returns a dummy callable that simply returns its argument. Usage::.

DTypeBoolean

alias of bool_

DTypeInteger

alias of Union[int8, int16, int32, int64, uint8, uint16, uint32, uint64]

DTypeFloating

alias of Union[float16, float32, float64]

DTypeNumber

alias of Union[int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64]

DTypeComplex

alias of Union[complex64, complex128]

DType

alias of Union[bool_, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, complex64, complex128]

Integer

alias of int

Floating

alias of float

Number

alias of Union[int, float]

Complex

alias of complex

Boolean

alias of bool

Literal

Special typing form to define literal types (a.k.a.

Dataclass

alias of Any

NestedSequence(*args, **kwargs)

A protocol for representing nested sequences.

ArrayLike

alias of Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]

IntegerOrArrayLike

alias of Union[int, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]

FloatingOrArrayLike

alias of Union[float, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]

NumberOrArrayLike

alias of Union[int, float, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]

ComplexOrArrayLike

alias of Union[complex, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]

BooleanOrArrayLike

alias of Union[bool, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]

ScalarType

Type variable.

StrOrArrayLike

alias of Union[str, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]

NDArray

alias of ndarray

IntegerOrNDArray

alias of Union[int, ndarray]

FloatingOrNDArray

alias of Union[float, ndarray]

NumberOrNDArray

alias of Union[int, float, ndarray]

ComplexOrNDArray

alias of Union[complex, ndarray]

BooleanOrNDArray

alias of Union[bool, ndarray]

StrOrNDArray

alias of Union[str, ndarray]

TypeInterpolator(*args, **kwargs)

TypeExtrapolator(*args, **kwargs)

TypeLUTSequenceItem(*args, **kwargs)

LiteralWarning

alias of Literal['default', 'error', 'ignore', 'always', 'module', 'once']

cast(typ, val)

Cast a value to a type.