From a817049e12d7009e1af30fd19694839502acc163 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 6 May 2022 02:50:55 -0400 Subject: [PATCH] Document that error responses can have a result object after all Also document some custom result types --- matrix_appservice_kakaotalk/kt/client/errors.py | 2 +- matrix_appservice_kakaotalk/kt/types/request.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/matrix_appservice_kakaotalk/kt/client/errors.py b/matrix_appservice_kakaotalk/kt/client/errors.py index 3dc77e3..a119c5f 100644 --- a/matrix_appservice_kakaotalk/kt/client/errors.py +++ b/matrix_appservice_kakaotalk/kt/client/errors.py @@ -28,7 +28,7 @@ class CommandException(Exception): In the case that different status codes map to the same error subclass, the status code can be retrieved from the "status" property. """ - # NOTE unsuccessful responses do not set a result, hence using RootCommandResult here + # TODO Handle result object # TODO Print _unrecognized? self.status = result.status self.message = _status_code_message_map.get(self.status, self._default_message) diff --git a/matrix_appservice_kakaotalk/kt/types/request.py b/matrix_appservice_kakaotalk/kt/types/request.py index 7d9c778..a0ebe7a 100644 --- a/matrix_appservice_kakaotalk/kt/types/request.py +++ b/matrix_appservice_kakaotalk/kt/types/request.py @@ -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. 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: