feat: support Array, Str, Bytes slice

This commit is contained in:
Shunsuke Shibayama 2023-07-15 12:29:07 +09:00
parent 579615d76e
commit 0152e368ab
14 changed files with 170 additions and 19 deletions

View file

@ -2,7 +2,6 @@ from _erg_result import Error
from _erg_int import Int
from _erg_control import then__
class Str(str):
def __instancecheck__(cls, obj):
return isinstance(obj, str)
@ -40,6 +39,15 @@ class Str(str):
def __mod__(self, other):
return then__(str.__mod__(other, self), Str)
def __getitem__(self, index_or_slice):
from _erg_range import Range
if isinstance(index_or_slice, slice):
return Str(str.__getitem__(self, index_or_slice))
elif isinstance(index_or_slice, Range):
return Str(str.__getitem__(self, index_or_slice.into_slice()))
else:
return str.__getitem__(self, index_or_slice)
class StrMut: # Inherits Str
value: Str