Compare commits

...

2 Commits

Author SHA1 Message Date
Bagatur
40882d2cfb fmt 2023-08-21 16:12:46 -07:00
Bagatur
ac3e87c1a0 rfc 2023-08-21 16:11:43 -07:00

View File

@@ -51,6 +51,7 @@ Input = TypeVar("Input")
# Output type should implement __concat__, as eg str, list, dict do
Output = TypeVar("Output")
Other = TypeVar("Other")
R = TypeVar("R", bound="Runnable")
class Runnable(Generic[Input, Output], ABC):
@@ -211,15 +212,18 @@ class Runnable(Generic[Input, Output], ABC):
return RunnableBinding(bound=self, kwargs=kwargs)
def with_fallbacks(
self,
self: R,
fallbacks: Sequence[Runnable[Input, Output]],
*,
exceptions_to_handle: Tuple[Type[BaseException]] = (Exception,),
) -> RunnableWithFallbacks[Input, Output]:
return RunnableWithFallbacks(
runnable=self,
fallbacks=fallbacks,
exceptions_to_handle=exceptions_to_handle,
) -> R:
return cast(
R,
RunnableWithFallbacks(
runnable=self,
fallbacks=fallbacks,
exceptions_to_handle=exceptions_to_handle,
),
)
""" --- Helper methods for Subclasses --- """
@@ -521,6 +525,9 @@ class RunnableWithFallbacks(Serializable, Runnable[Input, Output]):
class Config:
arbitrary_types_allowed = True
def __getattr__(self, item):
return getattr(self.runnable, item)
@property
def lc_serializable(self) -> bool:
return True