simplify generics
This commit is contained in:
parent
d5ba12b265
commit
e0b75b1514
3 changed files with 24 additions and 19 deletions
|
|
@ -1,13 +1,15 @@
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from ytdl_sub.script.types.resolvable import AnyType_1
|
from ytdl_sub.script.types.resolvable import AnyTypeReturnableA
|
||||||
from ytdl_sub.script.types.resolvable import AnyType_2
|
from ytdl_sub.script.types.resolvable import AnyTypeReturnableB
|
||||||
from ytdl_sub.script.types.resolvable import Boolean
|
from ytdl_sub.script.types.resolvable import Boolean
|
||||||
|
|
||||||
|
|
||||||
class SpecialFunctions:
|
class SpecialFunctions:
|
||||||
@staticmethod
|
@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:
|
if condition.value:
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,9 @@ from typing import Union
|
||||||
from typing import get_origin
|
from typing import get_origin
|
||||||
|
|
||||||
from ytdl_sub.script.functions import Functions
|
from ytdl_sub.script.functions import Functions
|
||||||
from ytdl_sub.script.types.resolvable import AnyType_0
|
from ytdl_sub.script.types.resolvable import AnyTypeReturnable
|
||||||
from ytdl_sub.script.types.resolvable import AnyType_1
|
from ytdl_sub.script.types.resolvable import AnyTypeReturnableA
|
||||||
from ytdl_sub.script.types.resolvable import AnyType_2
|
from ytdl_sub.script.types.resolvable import AnyTypeReturnableB
|
||||||
from ytdl_sub.script.types.resolvable import ArgumentType
|
from ytdl_sub.script.types.resolvable import ArgumentType
|
||||||
from ytdl_sub.script.types.resolvable import NamedType
|
from ytdl_sub.script.types.resolvable import NamedType
|
||||||
from ytdl_sub.script.types.resolvable import Resolvable
|
from ytdl_sub.script.types.resolvable import Resolvable
|
||||||
|
|
@ -278,12 +278,9 @@ class BuiltInFunction(Function):
|
||||||
if is_union(output_type):
|
if is_union(output_type):
|
||||||
union_types_list = []
|
union_types_list = []
|
||||||
for union_type in output_type.__args__:
|
for union_type in output_type.__args__:
|
||||||
if union_type == AnyType_0:
|
if union_type in (AnyTypeReturnable, AnyTypeReturnableA, AnyTypeReturnableB):
|
||||||
union_types_list.append(self._arg_output_type(self.args[0]))
|
generic_arg_index = self.input_spec.args.index(union_type)
|
||||||
elif union_type == AnyType_1:
|
union_types_list.append(self._arg_output_type(self.args[generic_arg_index]))
|
||||||
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]))
|
|
||||||
else:
|
else:
|
||||||
union_types_list.append(union_type)
|
union_types_list.append(union_type)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,19 +22,25 @@ class ArgumentType(NamedType, ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class AnyType_0(NamedType, ABC):
|
class AnyTypeReturnable(NamedType, ABC):
|
||||||
pass
|
"""
|
||||||
|
AnyType to express generics in functions that are part of the return type
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class AnyType_1(NamedType, ABC):
|
class AnyTypeReturnableA(NamedType, ABC):
|
||||||
pass
|
"""
|
||||||
|
AnyType to express generics in functions when more than one are present (i.e. `if`)
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class AnyType_2(NamedType, ABC):
|
class AnyTypeReturnableB(NamedType, ABC):
|
||||||
pass
|
"""
|
||||||
|
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
|
Human-readable name for FutureResolvable
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue