From 25f3cf795d51ae815fad4f6cc030579978c10275 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 23 Jun 2025 12:08:05 -0400 Subject: [PATCH] Add flag to toggle private vars in `Channel.pformat()` Call it `privates: bool` and only show certain internal instance vars when set in the `repr()` output. --- tractor/ipc/_chan.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tractor/ipc/_chan.py b/tractor/ipc/_chan.py index 2c3374c2..dd7b520f 100644 --- a/tractor/ipc/_chan.py +++ b/tractor/ipc/_chan.py @@ -196,9 +196,12 @@ class Channel: self._transport.codec = orig # TODO: do a .src/.dst: str for maddrs? - def pformat(self) -> str: + def pformat( + self, + privates: bool = False, + ) -> str: if not self._transport: - return '' + return '' tpt: MsgTransport = self._transport tpt_name: str = type(tpt).__name__ @@ -206,14 +209,17 @@ class Channel: 'connected' if self.connected() else 'closed' ) - return ( + repr_str: str = ( f'' + ) + ( f' |_msgstream: {tpt_name}\n' f' proto={tpt.laddr.proto_key!r}\n' f' layer={tpt.layer_key!r}\n' @@ -223,9 +229,13 @@ class Channel: f' stream={tpt.stream}\n' f' maddr={tpt.maddr!r}\n' f' drained={tpt.drained}\n' + ) + ( f' _send_lock={tpt._send_lock.statistics()}\n' - f')>\n' + if privates else '' + ) + ( + ')>\n' ) + return repr_str # NOTE: making this return a value that can be passed to # `eval()` is entirely **optional** FYI!