Skip to content

Commit 3bb4553

Browse files
committed
✨ support array-likes of nested sequences in _numtype.Casts*
1 parent 8c83725 commit 3bb4553

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/_numtype/_nep50.pyi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from typing import Any, Protocol, TypeAlias, type_check_only
66
from typing_extensions import TypeAliasType, TypeVar
77

88
import numpy as np
9+
from numpy._typing import _NestedSequence
910

1011
__all__ = [
1112
"Casts",
@@ -22,6 +23,7 @@ __all__ = [
2223

2324
###
2425

26+
_LikeT = TypeVar("_LikeT")
2527
_LikeT_co = TypeVar("_LikeT_co", covariant=True)
2628

2729
_BuitinT = TypeVar("_BuitinT")
@@ -125,14 +127,16 @@ class _LikeScalar(Protocol[_LikeT_co]):
125127

126128
###
127129

130+
_SequenceND: TypeAlias = _LikeT | _NestedSequence[_LikeT]
131+
128132
Casts = TypeAliasType(
129133
"Casts",
130-
_LikeNumeric[_CanNEP50[_ScalarOutT, Any, Any], _ShapeT],
134+
_SequenceND[_LikeNumeric[_CanNEP50[_ScalarOutT, Any, Any], _ShapeT]],
131135
type_params=(_ScalarOutT, _ShapeT),
132136
)
133137
CastsArray = TypeAliasType(
134138
"CastsArray",
135-
_LikeArray[_CanNEP50[_ScalarOutT, Any, Any], _ShapeT],
139+
_SequenceND[_LikeArray[_CanNEP50[_ScalarOutT, Any, Any], _ShapeT]],
136140
type_params=(_ScalarOutT, _ShapeT),
137141
)
138142
CastsScalar = TypeAliasType(
@@ -154,12 +158,12 @@ _CastWith: TypeAlias = (
154158
)
155159
CastsWith = TypeAliasType(
156160
"CastsWith",
157-
_LikeNumeric[_CastWith[_ScalarInT, _ScalarOutT], _ShapeT],
161+
_SequenceND[_LikeNumeric[_CastWith[_ScalarInT, _ScalarOutT], _ShapeT]],
158162
type_params=(_ScalarInT, _ScalarOutT, _ShapeT),
159163
)
160164
CastsWithArray = TypeAliasType(
161165
"CastsWithArray",
162-
_LikeArray[_CastWith[_ScalarInT, _ScalarOutT], _ShapeT],
166+
_SequenceND[_LikeArray[_CastWith[_ScalarInT, _ScalarOutT], _ShapeT]],
163167
type_params=(_ScalarInT, _ScalarOutT, _ShapeT),
164168
)
165169
CastsWithScalar = TypeAliasType(

0 commit comments

Comments
 (0)