You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / _typing / _nested_sequence / _NestedSequence

_ProtocolMeta

numpy._typing._nested_sequence:_NestedSequence

source: /numpy/_typing/_nested_sequence.py :13

Signature

def   _NestedSequence ( * args ** kwargs )

Members

Summary

A protocol for representing nested sequences.

Warnings

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

Examples

.. code-block:: python
from typing import TYPE_CHECKING
import numpy as np
from numpy._typing import _NestedSequence
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]]

See also

collections.abc.Sequence

ABCs for read-only and mutable sequences.

Aliases

  • numpy._typing._NestedSequence