mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 12:14:43 +00:00
feat: add Dimension
and unit
module
This commit is contained in:
parent
82848c10d6
commit
4651a383ae
16 changed files with 392 additions and 10 deletions
|
@ -24,3 +24,37 @@ Record = tuple
|
|||
|
||||
class Never:
|
||||
pass
|
||||
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
Ty = TypeVar('Ty')
|
||||
M = TypeVar('M', bound=int)
|
||||
L = TypeVar("L", bound=int)
|
||||
T = TypeVar("T", bound=int)
|
||||
I = TypeVar("I", bound=int)
|
||||
Θ = TypeVar("Θ", bound=int)
|
||||
N = TypeVar("N", bound=int)
|
||||
J = TypeVar("J", bound=int)
|
||||
class Dimension(float, Generic[Ty, M, L, T, I, Θ, N, J]):
|
||||
def value(self) -> float:
|
||||
return float(self)
|
||||
def __str__(self):
|
||||
return f"Dimension({float(self)})"
|
||||
def __add__(self, other):
|
||||
return Dimension(float(self) + other)
|
||||
def __sub__(self, other):
|
||||
return Dimension(float(self) - other)
|
||||
def __mul__(self, other):
|
||||
return Dimension(float(self) * other)
|
||||
def __rmul__(self, other):
|
||||
return Dimension(other * float(self))
|
||||
def __truediv__(self, other):
|
||||
return Dimension(float(self) / other)
|
||||
def __floordiv__(self, other):
|
||||
return Dimension(float(self) // other)
|
||||
def __rtruediv__(self, other):
|
||||
return Dimension(other / float(self))
|
||||
def __rfloordiv__(self, other):
|
||||
return Dimension(other // float(self))
|
||||
def type_check(self, t: type) -> bool:
|
||||
return t.__name__ == "Dimension"
|
||||
|
|
|
@ -25,10 +25,12 @@ class UnionType:
|
|||
|
||||
|
||||
class FakeGenericAlias:
|
||||
__name__: str
|
||||
__origin__: type
|
||||
__args__: list # list[type]
|
||||
|
||||
def __init__(self, origin, *args):
|
||||
self.__name__ = origin.__name__
|
||||
self.__origin__ = origin
|
||||
self.__args__ = args
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue