From f7ad35c9642bbf6432b2d12abfae7d97c2b53dbf Mon Sep 17 00:00:00 2001 From: Parnassius Date: Wed, 1 Jan 2025 16:38:27 +0100 Subject: [PATCH] `slice` is now generic --- domify/base_element.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/domify/base_element.py b/domify/base_element.py index 26ec3ea..aaba2cd 100644 --- a/domify/base_element.py +++ b/domify/base_element.py @@ -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) @@ -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): @@ -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: