Skip to content

Commit a2aa059

Browse files
committed
Add type overload for __getitem__
1 parent a0104e3 commit a2aa059

File tree

1 file changed

+7
-2
lines changed
  • src/power_grid_model_ds/_core/model/arrays/base

1 file changed

+7
-2
lines changed

src/power_grid_model_ds/_core/model/arrays/base/array.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections import namedtuple
77
from copy import copy
88
from functools import lru_cache
9-
from typing import Any, Iterable, Literal, Type, TypeVar
9+
from typing import Any, Iterable, Literal, Type, TypeVar, overload
1010

1111
import numpy as np
1212
from numpy.typing import ArrayLike, NDArray
@@ -152,7 +152,12 @@ def __setattr__(self: Self, attr: str, value: object) -> None:
152152
except (AttributeError, ValueError) as error:
153153
raise AttributeError(f"Cannot set attribute {attr} on {self.__class__.__name__}") from error
154154

155-
def __getitem__(self: Self, item):
155+
@overload
156+
def __getitem__(self: Self, item: str | list | tuple) -> NDArray[Any]: ...
157+
@overload
158+
def __getitem__(self: Self, item: Any) -> Self: ...
159+
160+
def __getitem__(self, item):
156161
"""Used by for-loops, slicing [0:3], column-access ['id'], row-access [0], multi-column access.
157162
Note: If a single item is requested, return a named tuple instead of a np.void object.
158163
"""

0 commit comments

Comments
 (0)