Skip to content

Commit

Permalink
Improve repr of operations (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhaldemar authored Dec 27, 2024
1 parent e3e6127 commit d4e6e9c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/yandex_cloud_ml_sdk/_types/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ async def _wait(

return await self._get_result(timeout=timeout)

def __repr__(self) -> str:
return f'{self.__class__.__name__}<id="{self.id}">'


class BaseOperation(Generic[ResultTypeT_co], OperationInterface[ResultTypeT_co]):
_last_known_status: OperationStatus | None
Expand All @@ -107,6 +110,17 @@ def __init__(
self._transformer = transformer or self._default_result_transofrmer
self._default_poll_timeout = default_poll_timeout

def __repr__(self) -> str:
arg_list = [
('id', repr(self.id)),
('result_type', self._result_type.__name__)
]
if self._service_name:
arg_list.append(('endpoint_name', self._service_name))

args = ', '.join('='.join((k, v)) for k, v in arg_list)
return f'{self.__class__.__name__}<{args}>'

# pylint: disable=unused-argument
async def _default_result_transofrmer(self, proto: Any, timeout: float) -> ResultTypeT_co:
# NB: mypy can't figure out that self._result_type._from_proto is
Expand Down

0 comments on commit d4e6e9c

Please sign in to comment.