diff --git a/src/ytdl_sub/script/functions/boolean_functions.py b/src/ytdl_sub/script/functions/boolean_functions.py index 51cf5fb8..3af1d53c 100644 --- a/src/ytdl_sub/script/functions/boolean_functions.py +++ b/src/ytdl_sub/script/functions/boolean_functions.py @@ -1,30 +1,29 @@ -from ytdl_sub.script.types.resolvable import Boolean -from ytdl_sub.script.types.resolvable import Resolvable +from ytdl_sub.script.types.resolvable import Boolean, AnyType class BooleanFunctions: @staticmethod - def bool(value: Resolvable) -> Boolean: + def bool(value: AnyType) -> Boolean: return Boolean(bool(value.value)) @staticmethod - def equals(left: Resolvable, right: Resolvable) -> Boolean: + def equals(left: AnyType, right: AnyType) -> Boolean: return Boolean(left.value == right.value) @staticmethod - def lt(left: Resolvable, right: Resolvable) -> Boolean: + def lt(left: AnyType, right: AnyType) -> Boolean: return Boolean(left.value < right.value) @staticmethod - def lte(left: Resolvable, right: Resolvable) -> Boolean: + def lte(left: AnyType, right: AnyType) -> Boolean: return Boolean(left.value <= right.value) @staticmethod - def gt(left: Resolvable, right: Resolvable) -> Boolean: + def gt(left: AnyType, right: AnyType) -> Boolean: return Boolean(left.value > right.value) @staticmethod - def gte(left: Resolvable, right: Resolvable) -> Boolean: + def gte(left: AnyType, right: AnyType) -> Boolean: return Boolean(left.value >= right.value) @staticmethod diff --git a/src/ytdl_sub/script/functions/map_functions.py b/src/ytdl_sub/script/functions/map_functions.py index cce728d1..230aac59 100644 --- a/src/ytdl_sub/script/functions/map_functions.py +++ b/src/ytdl_sub/script/functions/map_functions.py @@ -6,6 +6,7 @@ from ytdl_sub.script.types.array import Array from ytdl_sub.script.types.map import Map from ytdl_sub.script.types.resolvable import Hashable from ytdl_sub.script.types.resolvable import Resolvable +from ytdl_sub.script.types.resolvable import AnyType from ytdl_sub.script.types.resolvable import String from ytdl_sub.utils.exceptions import StringFormattingException @@ -26,7 +27,7 @@ class MapFunctions: return Map(output) @staticmethod - def get(mapping: Map, key: Hashable, default: Optional[Resolvable] = None) -> Resolvable: + def get(mapping: Map, key: Hashable, default: Optional[AnyType] = None) -> AnyType: if key not in mapping.value: if default is not None: return default diff --git a/src/ytdl_sub/script/functions/numeric_functions.py b/src/ytdl_sub/script/functions/numeric_functions.py index 2ded52da..8b194c70 100644 --- a/src/ytdl_sub/script/functions/numeric_functions.py +++ b/src/ytdl_sub/script/functions/numeric_functions.py @@ -1,7 +1,7 @@ from ytdl_sub.script.types.resolvable import Float from ytdl_sub.script.types.resolvable import Integer from ytdl_sub.script.types.resolvable import Numeric -from ytdl_sub.script.types.resolvable import Resolvable +from ytdl_sub.script.types.resolvable import AnyType def _to_numeric(value: int | float) -> Numeric: @@ -12,11 +12,11 @@ def _to_numeric(value: int | float) -> Numeric: class NumericFunctions: @staticmethod - def float(value: Resolvable) -> Float: + def float(value: AnyType) -> Float: return Float(value=float(value.value)) @staticmethod - def int(value: Resolvable) -> Integer: + def int(value: AnyType) -> Integer: return Integer(value=int(value.value)) @staticmethod diff --git a/src/ytdl_sub/script/functions/special_functions.py b/src/ytdl_sub/script/functions/special_functions.py index 8a312de5..9fe68419 100644 --- a/src/ytdl_sub/script/functions/special_functions.py +++ b/src/ytdl_sub/script/functions/special_functions.py @@ -1,16 +1,15 @@ from typing import Union from ytdl_sub.script.types.resolvable import Boolean -from ytdl_sub.script.types.resolvable import Resolvable -from ytdl_sub.script.types.resolvable import Resolvable_1 -from ytdl_sub.script.types.resolvable import Resolvable_2 +from ytdl_sub.script.types.resolvable import AnyType_1 +from ytdl_sub.script.types.resolvable import AnyType_2 class SpecialFunctions: @staticmethod def if_( - condition: Boolean, true: Resolvable, false: Resolvable - ) -> Union[Resolvable_1, Resolvable_2]: + condition: Boolean, true: AnyType_1, false: AnyType_2 + ) -> Union[AnyType_1, AnyType_2]: if condition.value: return true return false diff --git a/src/ytdl_sub/script/functions/string_functions.py b/src/ytdl_sub/script/functions/string_functions.py index 5d0f68ef..96f2df59 100644 --- a/src/ytdl_sub/script/functions/string_functions.py +++ b/src/ytdl_sub/script/functions/string_functions.py @@ -1,13 +1,13 @@ from typing import Optional from ytdl_sub.script.types.resolvable import Integer -from ytdl_sub.script.types.resolvable import Resolvable +from ytdl_sub.script.types.resolvable import AnyType from ytdl_sub.script.types.resolvable import String class StringFunctions: @staticmethod - def string(value: Resolvable) -> String: + def string(value: AnyType) -> String: return String(value=str(value.value)) @staticmethod diff --git a/src/ytdl_sub/script/types/array.py b/src/ytdl_sub/script/types/array.py index 418f8557..f5fb34ba 100644 --- a/src/ytdl_sub/script/types/array.py +++ b/src/ytdl_sub/script/types/array.py @@ -4,7 +4,7 @@ from typing import Dict from typing import List from typing import Set -from ytdl_sub.script.types.resolvable import ArgumentType +from ytdl_sub.script.types.resolvable import ArgumentType, FutureResolvable from ytdl_sub.script.types.resolvable import NonHashable from ytdl_sub.script.types.resolvable import Resolvable from ytdl_sub.script.types.resolvable import ResolvableToJson @@ -19,7 +19,7 @@ class Array(NonHashable): @dataclass(frozen=True) -class UnresolvedArray(Array, VariableDependency, ArgumentType): +class UnresolvedArray(Array, VariableDependency, FutureResolvable): value: List[ArgumentType] @property diff --git a/src/ytdl_sub/script/types/function.py b/src/ytdl_sub/script/types/function.py index 86b5c7b2..0554baa1 100644 --- a/src/ytdl_sub/script/types/function.py +++ b/src/ytdl_sub/script/types/function.py @@ -16,9 +16,9 @@ from typing import get_origin from ytdl_sub.script.functions import Functions from ytdl_sub.script.types.resolvable import ArgumentType from ytdl_sub.script.types.resolvable import Resolvable -from ytdl_sub.script.types.resolvable import Resolvable_0 -from ytdl_sub.script.types.resolvable import Resolvable_1 -from ytdl_sub.script.types.resolvable import Resolvable_2 +from ytdl_sub.script.types.resolvable import AnyType_0 +from ytdl_sub.script.types.resolvable import AnyType_1 +from ytdl_sub.script.types.resolvable import AnyType_2 from ytdl_sub.script.types.variable import FunctionArgument from ytdl_sub.script.types.variable import Variable from ytdl_sub.script.types.variable_dependency import VariableDependency @@ -245,11 +245,11 @@ class BuiltInFunction(Function): if is_union(output_type): union_types_list = [] for union_type in output_type.__args__: - if union_type == Resolvable_0: + if union_type == AnyType_0: union_types_list.append(type(self.args[0])) - elif union_type == Resolvable_1: + elif union_type == AnyType_1: union_types_list.append(type(self.args[1])) - elif union_type == Resolvable_2: + elif union_type == AnyType_2: union_types_list.append(type(self.args[2])) else: union_types_list.append(union_type) diff --git a/src/ytdl_sub/script/types/map.py b/src/ytdl_sub/script/types/map.py index 55ffeb71..b5fd206f 100644 --- a/src/ytdl_sub/script/types/map.py +++ b/src/ytdl_sub/script/types/map.py @@ -4,7 +4,7 @@ from typing import Dict from typing import List from typing import Set -from ytdl_sub.script.types.resolvable import ArgumentType +from ytdl_sub.script.types.resolvable import ArgumentType, FutureResolvable from ytdl_sub.script.types.resolvable import Hashable from ytdl_sub.script.types.resolvable import NonHashable from ytdl_sub.script.types.resolvable import Resolvable @@ -21,7 +21,7 @@ class Map(NonHashable): @dataclass(frozen=True) -class UnresolvedMap(Map, VariableDependency, ArgumentType): +class UnresolvedMap(Map, VariableDependency, FutureResolvable): value: Dict[ArgumentType, ArgumentType] @property diff --git a/src/ytdl_sub/script/types/resolvable.py b/src/ytdl_sub/script/types/resolvable.py index de204ff7..b63c3d12 100644 --- a/src/ytdl_sub/script/types/resolvable.py +++ b/src/ytdl_sub/script/types/resolvable.py @@ -11,25 +11,36 @@ NumericT = TypeVar("NumericT", bound=int | float) class ArgumentType(ABC): + """ + Any possible argument type that has not been resolved yet + """ + pass + +class AnyType(ArgumentType, ABC): + """ + Human-readable name for FutureResolvable + """ + value: Any + +class FutureResolvable(AnyType, ABC): + """ + Type that will be resolved in the future + """ + +class AnyType_0(FutureResolvable, ABC): pass -class Resolvable_0(ABC): +class AnyType_1(FutureResolvable, ABC): pass -class Resolvable_1(ABC): - pass - - -class Resolvable_2(ABC): +class AnyType_2(FutureResolvable, ABC): pass @dataclass(frozen=True) -class Resolvable(Resolvable_0, Resolvable_1, Resolvable_2, ABC): - value: Any - +class Resolvable(AnyType_0, AnyType_1, AnyType_2, ABC): def __str__(self) -> str: return str(self.value)