builtinfunctiontype
This commit is contained in:
parent
4278534c21
commit
fd9be6444e
5 changed files with 8 additions and 15 deletions
|
|
@ -4,7 +4,6 @@ from typing import List
|
|||
from typing import Optional
|
||||
from typing import Set
|
||||
|
||||
from ytdl_sub.script.functions import Functions
|
||||
from ytdl_sub.script.parser import parse
|
||||
from ytdl_sub.script.types.resolvable import Resolvable
|
||||
from ytdl_sub.script.types.syntax_tree import SyntaxTree
|
||||
|
|
@ -145,12 +144,6 @@ class Script:
|
|||
f"{nested_custom_function.num_input_args}"
|
||||
)
|
||||
|
||||
def _ensure_lambda_usage_num_input_arguments_valid(self) -> None:
|
||||
for variable_name, variable_definition in self._variables.items():
|
||||
for lambda_argument in variable_definition.lambda_arguments:
|
||||
if Functions.is_built_in(name=lambda_argument.value):
|
||||
pass
|
||||
|
||||
def _validate(self) -> None:
|
||||
self._ensure_no_custom_function_cycles()
|
||||
self._ensure_custom_function_arguments_valid()
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from ytdl_sub.script.functions import Functions
|
|||
from ytdl_sub.script.types.array import ResolvedArray
|
||||
from ytdl_sub.script.types.array import UnresolvedArray
|
||||
from ytdl_sub.script.types.resolvable import Argument
|
||||
from ytdl_sub.script.types.resolvable import BuiltInFunctionType
|
||||
from ytdl_sub.script.types.resolvable import FunctionType
|
||||
from ytdl_sub.script.types.resolvable import Lambda
|
||||
from ytdl_sub.script.types.resolvable import NamedCustomFunction
|
||||
|
|
@ -19,7 +20,6 @@ from ytdl_sub.script.types.resolvable import Resolvable
|
|||
from ytdl_sub.script.types.resolvable import ReturnableArgument
|
||||
from ytdl_sub.script.types.resolvable import ReturnableArgumentA
|
||||
from ytdl_sub.script.types.resolvable import ReturnableArgumentB
|
||||
from ytdl_sub.script.types.resolvable import TypeHintedFunctionType
|
||||
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
|
||||
|
|
@ -78,7 +78,7 @@ class CustomFunction(Function, NamedCustomFunction):
|
|||
raise UNREACHABLE
|
||||
|
||||
|
||||
class BuiltInFunction(Function, TypeHintedFunctionType):
|
||||
class BuiltInFunction(Function, BuiltInFunctionType):
|
||||
def validate_args(self) -> "BuiltInFunction":
|
||||
if not self.function_spec.is_compatible(input_args=self.args):
|
||||
raise FunctionArgumentsExceptionFormatter(
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ class FunctionType(NamedArgument, ABC):
|
|||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TypeHintedFunctionType(FunctionType, ABC):
|
||||
class BuiltInFunctionType(FunctionType, ABC):
|
||||
@abstractmethod
|
||||
def output_type(self) -> Type[Resolvable]:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ from typing import Type
|
|||
from typing import TypeVar
|
||||
from typing import Union
|
||||
|
||||
from ytdl_sub.script.types.resolvable import BuiltInFunctionType
|
||||
from ytdl_sub.script.types.resolvable import NamedType
|
||||
from ytdl_sub.script.types.resolvable import TypeHintedFunctionType
|
||||
from ytdl_sub.script.utils.exceptions import IncompatibleFunctionArguments
|
||||
from ytdl_sub.script.utils.exceptions import UserException
|
||||
from ytdl_sub.script.utils.type_checking import FunctionSpec
|
||||
|
|
@ -101,7 +101,7 @@ class FunctionArgumentsExceptionFormatter:
|
|||
def __init__(
|
||||
self,
|
||||
input_spec: FunctionSpec,
|
||||
function_instance: TypeHintedFunctionType,
|
||||
function_instance: BuiltInFunctionType,
|
||||
):
|
||||
self._args = input_spec.args
|
||||
self._varargs = input_spec.varargs
|
||||
|
|
@ -126,7 +126,7 @@ class FunctionArgumentsExceptionFormatter:
|
|||
def _received_args_str(self) -> str:
|
||||
received_type_names: List[str] = []
|
||||
for arg in self._input_args:
|
||||
if isinstance(arg, TypeHintedFunctionType):
|
||||
if isinstance(arg, BuiltInFunctionType):
|
||||
if is_union(arg.output_type()):
|
||||
received_type_names.append(
|
||||
f"%{arg.name}(...)->Union["
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ from typing import Union
|
|||
from typing import get_origin
|
||||
|
||||
from ytdl_sub.script.types.resolvable import Argument
|
||||
from ytdl_sub.script.types.resolvable import BuiltInFunctionType
|
||||
from ytdl_sub.script.types.resolvable import FunctionType
|
||||
from ytdl_sub.script.types.resolvable import Lambda
|
||||
from ytdl_sub.script.types.resolvable import NamedType
|
||||
from ytdl_sub.script.types.resolvable import Resolvable
|
||||
from ytdl_sub.script.types.resolvable import TypeHintedFunctionType
|
||||
from ytdl_sub.script.types.variable import Variable
|
||||
from ytdl_sub.script.utils.exceptions import UNREACHABLE
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ def is_type_compatible(
|
|||
True if arg is compatible with expected_arg_type. False otherwise.
|
||||
"""
|
||||
arg_type: Type[NamedType] = arg.__class__
|
||||
if isinstance(arg, FunctionType) and isinstance(arg, TypeHintedFunctionType):
|
||||
if isinstance(arg, BuiltInFunctionType):
|
||||
arg_type = arg.output_type() # built-in function
|
||||
elif isinstance(arg, FunctionType):
|
||||
return True # custom-function, can be anything, so pass for now
|
||||
|
|
|
|||
Loading…
Reference in a new issue