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) 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})"