Skip to content

Commit

Permalink
slice is now generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Parnassius committed Jan 1, 2025
1 parent 6d126b1 commit f7ad35c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions domify/base_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ def __getitem__(self, key: str) -> str | bool: ...
def __getitem__(self, key: int) -> BaseElement: ...

@overload
def __getitem__(self, key: slice) -> list[BaseElement]: ...
def __getitem__(
self, key: slice[int | None, int | None, int | None]
) -> list[BaseElement]: ...

def __getitem__(
self, key: str | int | slice
self, key: str | int | slice[int | None, int | None, int | None]
) -> str | bool | BaseElement | list[BaseElement]:
if isinstance(key, str):
return self._attributes.get(key, False)
Expand All @@ -284,11 +286,13 @@ def __setitem__(self, key: str, val: _T_attribute) -> None: ...
def __setitem__(self, key: int, val: _T_child) -> None: ...

@overload
def __setitem__(self, key: slice, val: Iterable[_T_child]) -> None: ...
def __setitem__(
self, key: slice[int | None, int | None, int | None], val: Iterable[_T_child]
) -> None: ...

def __setitem__(
self,
key: str | int | slice,
key: str | int | slice[int | None, int | None, int | None],
val: _T_attribute | _T_child | Iterable[_T_child],
) -> None:
if isinstance(key, str):
Expand All @@ -307,7 +311,9 @@ def __setitem__(
for child in children:
self._remove_from_stack(child)

def __delitem__(self, key: str | int | slice) -> None:
def __delitem__(
self, key: str | int | slice[int | None, int | None, int | None]
) -> None:
if isinstance(key, str):
del self._attributes[key]
else:
Expand Down

0 comments on commit f7ad35c

Please sign in to comment.