fix(TextHandler): Fixing an issue with slicing

Slicing was returning `TextHandlers` instead of `TextHandler`. This solves #41 and corrects the type hint
This commit is contained in:
Karim shoair
2025-03-05 03:11:46 +02:00
parent 573bfe030c
commit e9344a7384
+1 -12
View File
@@ -23,19 +23,8 @@ class TextHandler(str):
return super().__new__(cls, string)
return super().__new__(cls, '')
@typing.overload
def __getitem__(self, key: SupportsIndex) -> 'TextHandler':
pass
@typing.overload
def __getitem__(self, key: slice) -> "TextHandlers":
pass
def __getitem__(self, key: Union[SupportsIndex, slice]) -> Union["TextHandler", "TextHandlers"]:
def __getitem__(self, key: Union[SupportsIndex, slice]) -> "TextHandler":
lst = super().__getitem__(key)
if isinstance(key, slice):
lst = [TextHandler(s) for s in lst]
return TextHandlers(typing.cast(List[_TextHandlerType], lst))
return typing.cast(_TextHandlerType, TextHandler(lst))
def split(self, sep: str = None, maxsplit: SupportsIndex = -1) -> 'TextHandlers':