diff --git a/src/ytdl_sub/script/functions/special_functions.py b/src/ytdl_sub/script/functions/special_functions.py index 50ffdc21..76e47839 100644 --- a/src/ytdl_sub/script/functions/special_functions.py +++ b/src/ytdl_sub/script/functions/special_functions.py @@ -1,13 +1,15 @@ from typing import Union -from ytdl_sub.script.types.resolvable import AnyType_1 -from ytdl_sub.script.types.resolvable import AnyType_2 +from ytdl_sub.script.types.resolvable import AnyTypeReturnableA +from ytdl_sub.script.types.resolvable import AnyTypeReturnableB from ytdl_sub.script.types.resolvable import Boolean class SpecialFunctions: @staticmethod - def if_(condition: Boolean, true: AnyType_1, false: AnyType_2) -> Union[AnyType_1, AnyType_2]: + def if_( + condition: Boolean, true: AnyTypeReturnableA, false: AnyTypeReturnableB + ) -> Union[AnyTypeReturnableA, AnyTypeReturnableB]: if condition.value: return true return false diff --git a/src/ytdl_sub/script/types/function.py b/src/ytdl_sub/script/types/function.py index 17f1bf09..bffcc19c 100644 --- a/src/ytdl_sub/script/types/function.py +++ b/src/ytdl_sub/script/types/function.py @@ -14,9 +14,9 @@ from typing import Union from typing import get_origin from ytdl_sub.script.functions import Functions -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.resolvable import AnyTypeReturnable +from ytdl_sub.script.types.resolvable import AnyTypeReturnableA +from ytdl_sub.script.types.resolvable import AnyTypeReturnableB from ytdl_sub.script.types.resolvable import ArgumentType from ytdl_sub.script.types.resolvable import NamedType from ytdl_sub.script.types.resolvable import Resolvable @@ -278,12 +278,9 @@ class BuiltInFunction(Function): if is_union(output_type): union_types_list = [] for union_type in output_type.__args__: - if union_type == AnyType_0: - union_types_list.append(self._arg_output_type(self.args[0])) - elif union_type == AnyType_1: - union_types_list.append(self._arg_output_type(self.args[1])) - elif union_type == AnyType_2: - union_types_list.append(self._arg_output_type(self.args[2])) + if union_type in (AnyTypeReturnable, AnyTypeReturnableA, AnyTypeReturnableB): + generic_arg_index = self.input_spec.args.index(union_type) + union_types_list.append(self._arg_output_type(self.args[generic_arg_index])) else: union_types_list.append(union_type) diff --git a/src/ytdl_sub/script/types/resolvable.py b/src/ytdl_sub/script/types/resolvable.py index 7c22c578..095066fc 100644 --- a/src/ytdl_sub/script/types/resolvable.py +++ b/src/ytdl_sub/script/types/resolvable.py @@ -22,19 +22,25 @@ class ArgumentType(NamedType, ABC): """ -class AnyType_0(NamedType, ABC): - pass +class AnyTypeReturnable(NamedType, ABC): + """ + AnyType to express generics in functions that are part of the return type + """ -class AnyType_1(NamedType, ABC): - pass +class AnyTypeReturnableA(NamedType, ABC): + """ + AnyType to express generics in functions when more than one are present (i.e. `if`) + """ -class AnyType_2(NamedType, ABC): - pass +class AnyTypeReturnableB(NamedType, ABC): + """ + AnyType to express generics in functions when more than one are present (i.e. `if`) + """ -class AnyType(ArgumentType, AnyType_0, AnyType_1, AnyType_2, ABC): +class AnyType(ArgumentType, AnyTypeReturnable, AnyTypeReturnableA, AnyTypeReturnableB, ABC): """ Human-readable name for FutureResolvable """