moar
This commit is contained in:
parent
ca1fc6a227
commit
182bda9bf4
5 changed files with 38 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from ytdl_sub.script.functions.numeric_functions import NumericFunctions
|
||||
from ytdl_sub.script.functions.string_functions import StringFunctions
|
||||
|
||||
|
||||
class Functions(StringFunctions):
|
||||
class Functions(StringFunctions, NumericFunctions):
|
||||
pass
|
||||
|
|
|
|||
31
src/ytdl_sub/script/functions/numeric_functions.py
Normal file
31
src/ytdl_sub/script/functions/numeric_functions.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from ytdl_sub.script.types.resolvable import Float
|
||||
from ytdl_sub.script.types.resolvable import Integer
|
||||
from ytdl_sub.script.types.resolvable import Numeric
|
||||
|
||||
|
||||
def _to_numeric(value: int | float) -> Numeric:
|
||||
if int(value) == value:
|
||||
return Integer(value=value)
|
||||
return Float(value=value)
|
||||
|
||||
|
||||
class NumericFunctions:
|
||||
@staticmethod
|
||||
def add(left: Numeric, right: Numeric) -> Numeric:
|
||||
return _to_numeric(left.value + right.value)
|
||||
|
||||
@staticmethod
|
||||
def sub(left: Numeric, right: Numeric) -> Numeric:
|
||||
return _to_numeric(left.value - right.value)
|
||||
|
||||
@staticmethod
|
||||
def mul(left: Numeric, right: Numeric) -> Numeric:
|
||||
return _to_numeric(left.value * right.value)
|
||||
|
||||
@staticmethod
|
||||
def div(left: Numeric, right: Numeric) -> Numeric:
|
||||
return _to_numeric(left.value / right.value)
|
||||
|
||||
@staticmethod
|
||||
def mod(value: Integer, modulo: Integer) -> Integer:
|
||||
return Integer(value=value.value % modulo.value)
|
||||
|
|
@ -3,9 +3,9 @@ from typing import List
|
|||
from typing import Optional
|
||||
from typing import Set
|
||||
|
||||
from ytdl_sub.script.functions import Resolvable
|
||||
from ytdl_sub.script.parser import parse
|
||||
from ytdl_sub.script.syntax_tree import SyntaxTree
|
||||
from ytdl_sub.script.types.resolvable import Resolvable
|
||||
from ytdl_sub.script.types.variable import Variable
|
||||
from ytdl_sub.utils.exceptions import StringFormattingException
|
||||
|
||||
|
|
|
|||
|
|
@ -133,13 +133,13 @@ class Function(VariableDependency):
|
|||
received_type_names: List[str] = []
|
||||
for arg in self.args:
|
||||
if isinstance(arg, Function):
|
||||
received_type_names.append(f"{arg.name}(...)->{arg.output_type.__name__}")
|
||||
received_type_names.append(f"%{arg.name}(...)->{arg.output_type.__name__}")
|
||||
else:
|
||||
received_type_names.append(arg.__class__.__name__)
|
||||
|
||||
received_args_str = f"({', '.join([name for name in received_type_names])})"
|
||||
|
||||
return f"Expected {self.input_spec.expected_args_str()}.\nReceived ({received_args_str})"
|
||||
return f"Expected {self.input_spec.expected_args_str()}.\nReceived {received_args_str}"
|
||||
|
||||
@property
|
||||
def callable(self) -> Callable[..., Resolvable]:
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ class Numeric(ResolvableT[NumericT], ABC, Generic[NumericT]):
|
|||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Integer(ResolvableT[int]):
|
||||
class Integer(Numeric[int]):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Float(ResolvableT[float]):
|
||||
class Float(Numeric[float]):
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue