Skip to content

Commit 61bb56b

Browse files
BvB93Bas van Beek
authored andcommitted
MAINT: Allow void.__getitem__ to take strings or lists thereof
1 parent 4093099 commit 61bb56b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

numpy/__init__.pyi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,8 +3273,15 @@ class void(flexible):
32733273
def setfield(
32743274
self, val: ArrayLike, dtype: DTypeLike, offset: int = ...
32753275
) -> None: ...
3276-
def __getitem__(self, key: SupportsIndex) -> Any: ...
3277-
def __setitem__(self, key: SupportsIndex, value: ArrayLike) -> None: ...
3276+
@overload
3277+
def __getitem__(self, key: str | SupportsIndex) -> Any: ...
3278+
@overload
3279+
def __getitem__(self, key: list[str]) -> void: ...
3280+
def __setitem__(
3281+
self,
3282+
key: str | List[str] | SupportsIndex,
3283+
value: ArrayLike,
3284+
) -> None: ...
32783285

32793286
void0 = void
32803287

numpy/typing/tests/data/reveal/scalars.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
m: np.timedelta64
1111
U: np.str_
1212
S: np.bytes_
13+
V: np.void
1314

1415
reveal_type(c8.real) # E: {float32}
1516
reveal_type(c8.imag) # E: {float32}
@@ -36,6 +37,11 @@
3637
reveal_type(np.unicode_('foo')) # E: numpy.str_
3738
reveal_type(np.str0('foo')) # E: numpy.str_
3839

40+
reveal_type(V[0]) # E: Any
41+
reveal_type(V["field1"]) # E: Any
42+
reveal_type(V[["field1", "field2"]]) # E: numpy.void
43+
V[0] = 5
44+
3945
# Aliases
4046
reveal_type(np.unicode_()) # E: numpy.str_
4147
reveal_type(np.str0()) # E: numpy.str_

0 commit comments

Comments
 (0)