|
|
|
@ -93,6 +93,7 @@ class RootCommandResult(ResponseState): |
|
|
|
|
ResultType = TypeVar("ResultType", bound=Serializable) |
|
|
|
|
|
|
|
|
|
def ResultListType(result_type: Type[ResultType]): |
|
|
|
|
"""Custom type for setting a result to a list of serializable objects.""" |
|
|
|
|
class _ResultListType(list[result_type], Serializable): |
|
|
|
|
def serialize(self) -> list[JSON]: |
|
|
|
|
return [v.serialize() for v in self] |
|
|
|
@ -104,6 +105,7 @@ def ResultListType(result_type: Type[ResultType]): |
|
|
|
|
return _ResultListType |
|
|
|
|
|
|
|
|
|
def ResultRawType(result_type: Type): |
|
|
|
|
"""Custom type for setting a result to a primitive.""" |
|
|
|
|
class _ResultRawType(result_type, Serializable): |
|
|
|
|
def serialize(self) -> result_type: |
|
|
|
|
return self |
|
|
|
@ -132,6 +134,7 @@ def deserialize_result( |
|
|
|
|
) -> Union[CommandResultDoneValue[ResultType], RootCommandResult]: |
|
|
|
|
"""Returns equivalent of CommandResult<T>. Does no consistency checking on success & result properties.""" |
|
|
|
|
if "result" in data and data.get("success"): |
|
|
|
|
# TODO Handle result object in unsuccessful response |
|
|
|
|
# TODO Allow arbitrary result object? |
|
|
|
|
return CommandResultDoneValue.deserialize_result(result_type, data) |
|
|
|
|
else: |
|
|
|
|