mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
Fix builtin types methods
This commit is contained in:
parent
8cdc735486
commit
d5e9649172
5 changed files with 107 additions and 101 deletions
|
@ -10,29 +10,29 @@ class Float(float):
|
|||
def mutate(self):
|
||||
return FloatMut(self)
|
||||
def __add__(self, other):
|
||||
return then__(super().__add__(other), Float)
|
||||
return then__(float.__add__(self, other), Float)
|
||||
def __radd__(self, other):
|
||||
return then__(super().__radd__(other), Float)
|
||||
return then__(float.__add__(other, self), Float)
|
||||
def __sub__(self, other):
|
||||
return then__(super().__sub__(other), Float)
|
||||
return then__(float.__sub__(self, other), Float)
|
||||
def __rsub__(self, other):
|
||||
return then__(super().__rsub__(other), Float)
|
||||
return then__(float.__sub__(other, self), Float)
|
||||
def __mul__(self, other):
|
||||
return then__(super().__mul__(other), Float)
|
||||
return then__(float.__mul__(self, other), Float)
|
||||
def __rmul__(self, other):
|
||||
return then__(super().__rmul__(other), Float)
|
||||
return then__(float.__mul__(other, self), Float)
|
||||
def __div__(self, other):
|
||||
return then__(super().__div__(other), Float)
|
||||
return then__(float.__div__(self, other), Float)
|
||||
def __rdiv__(self, other):
|
||||
return then__(super().__rdiv__(other), Float)
|
||||
return then__(float.__div__(other, self), Float)
|
||||
def __floordiv__(self, other):
|
||||
return then__(super().__floordiv__(other), Float)
|
||||
return then__(float.__floordiv__(self, other), Float)
|
||||
def __rfloordiv__(self, other):
|
||||
return then__(super().__rfloordiv__(other), Float)
|
||||
return then__(float.__floordiv__(other, self), Float)
|
||||
def __pow__(self, other):
|
||||
return then__(super().__pow__(other), Float)
|
||||
return then__(float.__pow__(self, other), Float)
|
||||
def __rpow__(self, other):
|
||||
return then__(super().__rpow__(other), Float)
|
||||
return then__(float.__pow__(other, self), Float)
|
||||
|
||||
class FloatMut(): # inherits Float
|
||||
value: Float
|
||||
|
|
|
@ -14,29 +14,29 @@ class Int(int):
|
|||
def mutate(self):
|
||||
return IntMut(self)
|
||||
def __add__(self, other):
|
||||
return then__(super().__add__(other), Int)
|
||||
return then__(int.__add__(self, other), Int)
|
||||
def __radd__(self, other):
|
||||
return then__(super().__radd__(other), Int)
|
||||
return then__(int.__add__(other, self), Int)
|
||||
def __sub__(self, other):
|
||||
return then__(super().__sub__(other), Int)
|
||||
return then__(int.__sub__(self, other), Int)
|
||||
def __rsub__(self, other):
|
||||
return then__(super().__rsub__(other), Int)
|
||||
return then__(int.__sub__(other, self), Int)
|
||||
def __mul__(self, other):
|
||||
return then__(super().__mul__(other), Int)
|
||||
return then__(int.__mul__(self, other), Int)
|
||||
def __rmul__(self, other):
|
||||
return then__(super().__rmul__(other), Int)
|
||||
return then__(int.__mul__(other, self), Int)
|
||||
def __div__(self, other):
|
||||
return then__(super().__div__(other), Int)
|
||||
return then__(int.__div__(self, other), Int)
|
||||
def __rdiv__(self, other):
|
||||
return then__(super().__rdiv__(other), Int)
|
||||
return then__(int.__div__(other, self), Int)
|
||||
def __floordiv__(self, other):
|
||||
return then__(super().__floordiv__(other), Int)
|
||||
return then__(int.__floordiv__(self, other), Int)
|
||||
def __rfloordiv__(self, other):
|
||||
return then__(super().__rfloordiv__(other), Int)
|
||||
return then__(int.__floordiv__(other, self), Int)
|
||||
def __pow__(self, other):
|
||||
return then__(super().__pow__(other), Int)
|
||||
return then__(int.__pow__(self, other), Int)
|
||||
def __rpow__(self, other):
|
||||
return then__(super().__rpow__(other), Int)
|
||||
return then__(int.__pow__(other, self), Int)
|
||||
|
||||
class IntMut(): # inherits Int
|
||||
value: Int
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from _erg_result import Error
|
||||
from _erg_int import Int, IntMut
|
||||
from _erg_int import Int
|
||||
from _erg_int import IntMut # don't unify with the above line
|
||||
from _erg_control import then__
|
||||
|
||||
class Nat(Int):
|
||||
|
|
|
@ -20,13 +20,13 @@ class Str(str):
|
|||
def to_int(self):
|
||||
return Int(self) if self.isdigit() else None
|
||||
def __add__(self, other):
|
||||
return then__(super().__add__(other), Str)
|
||||
return then__(str.__add__(self, other), Str)
|
||||
def __radd__(self, other):
|
||||
return then__(super().__radd__(other), Str)
|
||||
return then__(str.__add__(other, self), Str)
|
||||
def __mul__(self, other):
|
||||
return then__(super().__mul__(other), Str)
|
||||
return then__(str.__mul__(self, other), Str)
|
||||
def __mod__(self, other):
|
||||
return then__(super().__mod__(other), Str)
|
||||
return then__(str.__mod__(other, self), Str)
|
||||
|
||||
class StrMut(): # Inherits Str
|
||||
value: Str
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue