class documentation

class _NestedSequence(Protocol[_T_co]):

View In Hierarchy

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 :term:`sequences`.

Examples

>>> from __future__ import annotations

>>> from typing import TYPE_CHECKING
>>> import numpy as np
>>> from numpy.typing import _NestedSequnce

>>> def get_dtype(seq: _NestedSequnce[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]]
Method __contains__ Implement x in self.
Method __getitem__ Implement self[x].
Method __iter__ Implement iter(self).
Method __len__ Implement len(self).
Method __reversed__ Implement reversed(self).
Method count Return the number of occurrences of value.
Method index Return the first index of value.
def __contains__(self, x, /):
Implement x in self.
Parameters
x:objectUndocumented
Returns
boolUndocumented
def __getitem__(self, index, /):
Implement self[x].
def __iter__(self, /):
Implement iter(self).
Returns
Iterator[_T_co|_NestedSequence[_T_co]]Undocumented
def __len__(self, /):
Implement len(self).
Returns
intUndocumented
def __reversed__(self, /):
Implement reversed(self).
Returns
Iterator[_T_co|_NestedSequence[_T_co]]Undocumented
def count(self, value, /):
Return the number of occurrences of value.
Parameters
value:AnyUndocumented
Returns
intUndocumented
def index(self, value, /):
Return the first index of value.
Parameters
value:AnyUndocumented
Returns
intUndocumented