Skip to content

Commit 54bd855

Browse files
authored
fix: make Delegate classes proper ABCs with abstract methods (gnachman#602)
All four Delegate classes (tmux.Delegate, Session.Delegate, Tab.Delegate, Window.Delegate) used @abc.abstractmethod on methods but did not inherit from abc.ABC, so the decorator had no effect. - Add abc.ABC as base class to all four Delegate classes - Add ellipsis (...) as method body for all abstract methods - Remove misplaced @abc.abstractmethod class decorator from tmux.Delegate and add it to individual methods instead The only subclass (App) already implements all required methods.
1 parent 7803280 commit 54bd855

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

api/library/python/iterm2/iterm2/session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,27 @@ class Session:
175175
Represents an iTerm2 session.
176176
"""
177177

178-
class Delegate:
178+
class Delegate(abc.ABC):
179179
"""
180180
Provides callbacks for Session.
181181
"""
182182
@abc.abstractmethod
183183
def session_delegate_get_tab(
184184
self, session) -> typing.Optional['iterm2.Tab']:
185185
"""Returns the tab for a session."""
186+
...
186187

187188
@abc.abstractmethod
188189
def session_delegate_get_window(
189190
self, session) -> typing.Optional['iterm2.Window']:
190191
"""Returns the window for a session."""
192+
...
191193

192194
@abc.abstractmethod
193195
async def session_delegate_create_session(
194196
self, session_id: str) -> typing.Optional['iterm2.session.Session']:
195197
"""Creates a new Session object given a session ID."""
198+
...
196199

197200
delegate: typing.Optional[Delegate] = None
198201

api/library/python/iterm2/iterm2/tab.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@ class Tab:
2525
Don't create this yourself. Instead, use :class:`~iterm2.App`."""
2626

2727
# pylint: disable=too-few-public-methods
28-
class Delegate:
28+
class Delegate(abc.ABC):
2929
"""Delegate for Tab."""
3030
@abc.abstractmethod
3131
def tab_delegate_get_window(
3232
self, tab: 'Tab') -> typing.Optional['iterm2.window.Window']:
3333
"""Returns the Window for a Tab."""
34+
...
3435

3536
@abc.abstractmethod
3637
async def tab_delegate_get_window_by_id(
3738
self,
3839
window_id: str) -> typing.Optional['iterm2.window.Window']:
3940
"""Returns the Window with the given ID."""
41+
...
4042
# pylint: enable=too-few-public-methods
4143

4244
delegate: typing.Optional[Delegate] = None

api/library/python/iterm2/iterm2/tmux.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@
1111
import iterm2.window
1212

1313

14-
@abc.abstractmethod
15-
class Delegate:
14+
class Delegate(abc.ABC):
1615
"""Delegate interface for tmux."""
16+
@abc.abstractmethod
1717
async def tmux_delegate_async_get_window_for_tab_id(
1818
self, tab_id: str) -> typing.Optional[iterm2.window.Window]:
1919
"""Refreshes and gets the window for the specified tab."""
20+
...
2021

22+
@abc.abstractmethod
2123
def tmux_delegate_get_session_by_id(
2224
self, session_id: str) -> typing.Optional[iterm2.session.Session]:
2325
"""Returns the session with the given ID."""
26+
...
2427

28+
@abc.abstractmethod
2529
def tmux_delegate_get_connection(self) -> iterm2.connection.Connection:
2630
"""Returns the connection."""
31+
...
2732

2833

2934
DELEGATE: typing.Optional[Delegate] = None

api/library/python/iterm2/iterm2/window.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,28 @@ class Window:
4646
:meth:`async_create`.
4747
"""
4848

49-
class Delegate:
49+
class Delegate(abc.ABC):
5050
"""Delegate for Window"""
5151
@abc.abstractmethod
5252
async def window_delegate_get_window_with_session_id(
5353
self,
5454
session_id: str) -> typing.Optional['Window']:
5555
"""Gets the Window that contains a Session by ID."""
56+
...
5657

5758
@abc.abstractmethod
5859
async def window_delegate_get_tab_by_id(
5960
self,
6061
tab_id: str) -> typing.Optional[iterm2.tab.Tab]:
6162
"""Gets a Tab by ID."""
63+
...
6264

6365
@abc.abstractmethod
6466
async def window_delegate_get_tab_with_session_id(
6567
self,
6668
session_id: str) -> typing.Optional[iterm2.tab.Tab]:
6769
"""Returns the Tab containing a Session by ID."""
70+
...
6871

6972
delegate: typing.Optional[Delegate] = None
7073

0 commit comments

Comments
 (0)