Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve repr of operations #50

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading