From d55b1a4cbc9cae5f3ce8c52e321583fda5b8b6f7 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 25 Nov 2023 13:10:59 -0600 Subject: [PATCH 1/2] fix(pane,session,server): Return False if type mismatched --- src/libtmux/pane.py | 5 +++-- src/libtmux/server.py | 11 ++++++----- src/libtmux/session.py | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libtmux/pane.py b/src/libtmux/pane.py index 464b48354..23c3f434c 100644 --- a/src/libtmux/pane.py +++ b/src/libtmux/pane.py @@ -378,8 +378,9 @@ def reset(self) -> "Pane": # Dunder # def __eq__(self, other: object) -> bool: - assert isinstance(other, Pane) - return self.pane_id == other.pane_id + if isinstance(other, Pane): + return self.pane_id == other.pane_id + return False def __repr__(self) -> str: return f"{self.__class__.__name__}({self.pane_id} {self.window})" diff --git a/src/libtmux/server.py b/src/libtmux/server.py index 4a931bbff..da0f8db6e 100644 --- a/src/libtmux/server.py +++ b/src/libtmux/server.py @@ -560,11 +560,12 @@ def panes(self) -> QueryList[Pane]: # type:ignore # Dunder # def __eq__(self, other: object) -> bool: - assert isinstance(other, Server) - return ( - self.socket_name == other.socket_name - and self.socket_path == other.socket_path - ) + if isinstance(other, Server): + return ( + self.socket_name == other.socket_name + and self.socket_path == other.socket_path + ) + return False def __repr__(self) -> str: if self.socket_name is not None: diff --git a/src/libtmux/session.py b/src/libtmux/session.py index cd6c86cc9..fd0285bee 100644 --- a/src/libtmux/session.py +++ b/src/libtmux/session.py @@ -559,8 +559,9 @@ def attached_pane(self) -> t.Optional["Pane"]: # Dunder # def __eq__(self, other: object) -> bool: - assert isinstance(other, Session) - return self.session_id == other.session_id + if isinstance(other, Session): + return self.session_id == other.session_id + return False def __repr__(self) -> str: return f"{self.__class__.__name__}({self.session_id} {self.session_name})" From 1372f4409a714930c936f24edc0ee7fd6bfd84b5 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 25 Nov 2023 13:15:54 -0600 Subject: [PATCH 2/2] docs(CHANGES): Note __eq__ fixes --- CHANGES | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index d29d70467..4bb643a2a 100644 --- a/CHANGES +++ b/CHANGES @@ -16,8 +16,9 @@ $ pip install --user --upgrade --pre libtmux ### Improvement -- `Window.__eq__` now returns `False` instead of raising `AssertionError`, thank - you @m1guelperez! (#505) +- `Server.__eq__`, `Session.__eq__`, `Window.__eq__`, `Pane.__eq__` now returns `False` instead of raising `AssertionError` when type mismatches (#505, #510) + + Thank you @m1guelperez for `Window.__eq__`! (#505) ## libtmux 0.24.1 (2023-11-23)