Johan B.W. de Vries 13dc426fc5 It lives \o/
2023-04-11 11:35:08 +02:00

74 lines
1.8 KiB
Python

from typing import Any, Callable, List
from .value import Value
from .valuetype import ValueType
class MethodArgument:
__slots__ = ('name', 'value_type', )
name: str
value_type: ValueType
def __init__(self, name: str, value_type: ValueType) -> None:
self.name = name
self.value_type = value_type
def __eq__(self, other: Any) -> bool:
if not isinstance(other, MethodArgument):
raise NotImplementedError
return self.name == other.name and self.value_type == other.value_type
def __repr__(self) -> str:
return f'MethodArgument({repr(self.name)}, {repr(self.value_type)})'
class Method:
__slots__ = ('name', 'args', 'return_type', )
name: str
args: List[MethodArgument]
return_type: ValueType
def __init__(self, name: str, args: List[MethodArgument], return_type: ValueType) -> None:
self.name = name
self.args = args
self.return_type = return_type
def __repr__(self) -> str:
return f'Method({repr(self.name)}, {repr(self.args)}, {repr(self.return_type)})'
class MethodCallError:
pass
class MethodNotFoundError(MethodCallError):
pass
class MethodCall:
__slots__ = ('method', 'args', 'on_success', 'on_error', )
method: Method
args: List[Value]
on_success: Callable[[Value], None]
on_error: Callable[[MethodCallError], None]
def __init__(
self,
method: Method,
args: List[Value],
on_success: Callable[[Value], None],
on_error: Callable[[MethodCallError], None],
) -> None:
self.method = method
self.args = args
self.on_success = on_success
self.on_error = on_error
def __repr__(self) -> str:
return f'MethodCall({repr(self.method)}, {repr(self.args)}, {repr(self.on_success)}, {repr(self.on_error)})'