fix(awel): Fix awel check empty data bug (#1311)

This commit is contained in:
Fangyin Cheng 2024-03-19 18:56:57 +08:00 committed by GitHub
parent 4970c9f813
commit 86a7b6c6f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -33,6 +33,19 @@ class _EMPTY_DATA_TYPE:
def __str__(self):
return f"EmptyData({self.name})"
def is_same(self, obj: Any) -> bool:
"""Check if the object is the same as the current object.
Args:
obj (Any): The object to compare with.
Returns:
bool: True if the object is the same as the current object, False otherwise.
"""
if not isinstance(obj, _EMPTY_DATA_TYPE):
return False
return self == obj
EMPTY_DATA = _EMPTY_DATA_TYPE("EMPTY_DATA")
SKIP_DATA = _EMPTY_DATA_TYPE("SKIP_DATA")

View File

@ -76,7 +76,7 @@ class SimpleTaskOutput(TaskOutput[T], Generic[T]):
@property
def output(self) -> T:
"""Return the output data."""
if self._data == EMPTY_DATA:
if EMPTY_DATA.is_same(self._data):
raise ValueError("No output data for current task output")
return cast(T, self._data)
@ -188,7 +188,7 @@ class SimpleStreamTaskOutput(TaskOutput[T], Generic[T]):
Raises:
ValueError: If the output data is empty.
"""
if self._data == EMPTY_DATA:
if EMPTY_DATA.is_same(self._data):
raise ValueError("No output data for current task output")
return cast(AsyncIterator[T], self._data)