Fix builtin types methods

This commit is contained in:
Shunsuke Shibayama 2023-02-03 00:23:42 +09:00
parent c56ef64576
commit 8cdc735486
12 changed files with 180 additions and 7 deletions

View file

@ -1,5 +1,6 @@
from _erg_result import Error
from _erg_int import Int
from _erg_control import then__
class Str(str):
def __instancecheck__(cls, obj):
@ -18,6 +19,14 @@ class Str(str):
return StrMut(self)
def to_int(self):
return Int(self) if self.isdigit() else None
def __add__(self, other):
return then__(super().__add__(other), Str)
def __radd__(self, other):
return then__(super().__radd__(other), Str)
def __mul__(self, other):
return then__(super().__mul__(other), Str)
def __mod__(self, other):
return then__(super().__mod__(other), Str)
class StrMut(): # Inherits Str
value: Str