2023-12-11 10:44:37 +08:00
|
|
|
from typing import TypeVar, Sequence, Generic, Type
|
|
|
|
|
2023-12-08 11:25:26 +08:00
|
|
|
from pydantic import BaseConfig, BaseModel
|
|
|
|
|
2023-12-11 10:44:37 +08:00
|
|
|
Other = TypeVar("Other")
|
|
|
|
|
|
|
|
Input = TypeVar("Input", contravariant=True)
|
|
|
|
Output = TypeVar("Output", covariant=True)
|
2023-12-08 11:25:26 +08:00
|
|
|
|
2023-12-11 10:44:37 +08:00
|
|
|
|
2023-12-18 13:46:44 +08:00
|
|
|
class Runnable(BaseModel):
|
2023-12-08 11:25:26 +08:00
|
|
|
|
2023-12-15 17:33:54 +08:00
|
|
|
_last: bool = False
|
2023-12-08 11:25:26 +08:00
|
|
|
|
|
|
|
@property
|
2023-12-11 10:44:37 +08:00
|
|
|
def input_types(self) -> Type[Input]:
|
2023-12-08 11:25:26 +08:00
|
|
|
return
|
|
|
|
|
|
|
|
@property
|
2023-12-11 10:44:37 +08:00
|
|
|
def output_types(self) -> Type[Output]:
|
2023-12-08 11:25:26 +08:00
|
|
|
return
|
|
|
|
|
2023-12-11 10:44:37 +08:00
|
|
|
def invoke(self, input: Input) -> Sequence[Output]:
|
2023-12-08 11:25:26 +08:00
|
|
|
raise NotImplementedError("To be implemented in subclass")
|
|
|
|
|
2023-12-11 10:44:37 +08:00
|
|
|
def __rshift__(self, other: Other):
|
2023-12-08 11:25:26 +08:00
|
|
|
raise NotImplementedError("To be implemented in subclass")
|
|
|
|
|
|
|
|
class Config(BaseConfig):
|
2023-12-11 10:44:37 +08:00
|
|
|
arbitrary_types_allowed = True
|