colour.hints.NestedSequence#

class colour.hints.NestedSequence(*args, **kwargs)[source]#

A protocol for representing nested sequences.

Warning

NestedSequence currently does not work in combination with typevars, e.g. def func(a: _NestedSequnce[T]) -> T: ....

See also

collections.abc.Sequence

ABCs for read-only and mutable sequences.

Examples

>>> from __future__ import annotations
>>> from typing import TYPE_CHECKING
>>> import numpy as np
>>> def get_dtype(seq: NestedSequence[float]) -> np.dtype[np.float64]:
...     return np.asarray(seq).dtype
>>> a = get_dtype([1.0])
>>> b = get_dtype([[1.0]])
>>> c = get_dtype([[[1.0]]])
>>> d = get_dtype([[[[1.0]]]])
>>> if TYPE_CHECKING:
...     reveal_locals()
...     # note: Revealed local types are:
...     # note:     a: numpy.dtype[numpy.floating[numpy._typing._64Bit]]
...     # note:     b: numpy.dtype[numpy.floating[numpy._typing._64Bit]]
...     # note:     c: numpy.dtype[numpy.floating[numpy._typing._64Bit]]
...     # note:     d: numpy.dtype[numpy.floating[numpy._typing._64Bit]]
...
__init__(*args, **kwargs)#

Methods

__init__(*args, **kwargs)

count(value)

Return the number of occurrences of value.

index(value)

Return the first index of value.