Skip to content

Commit 7b6ad6d

Browse files
committed
!squash more
1 parent 4d04c61 commit 7b6ad6d

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

libtmux/session.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ def by(val: SessionDict) -> bool:
8282
return False
8383
return True
8484

85-
# TODO add type hint
8685
target_sessions = [s for s in self.server._sessions if by(s)]
87-
# target_sessions = list(filter(by, self.server._sessions))
8886
try:
8987
return target_sessions[0]
9088
except IndexError as e:

libtmux/window.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
PaneDict,
1919
TmuxMappingObject,
2020
TmuxRelationalObject,
21+
WindowDict,
2122
WindowOptionDict,
2223
handle_option_error,
2324
)
@@ -58,16 +59,13 @@ class Window(TmuxMappingObject, TmuxRelationalObject):
5859
session: "Session"
5960
""":class:`libtmux.Session` window is linked to"""
6061

61-
def __init__(self, session: "Session", **kwargs) -> None:
62+
def __init__(self, session: "Session", window_id: str, **kwargs: t.Any) -> None:
6263
self.session = session
6364
self.server = self.session.server
6465

65-
if "window_id" not in kwargs:
66-
raise ValueError("Window requires a `window_id`")
66+
self._window_id = window_id
6767

68-
self._window_id = kwargs["window_id"]
69-
70-
def __repr__(self):
68+
def __repr__(self) -> str:
7169
return "{}({} {}:{}, {})".format(
7270
self.__class__.__name__,
7371
self.id,
@@ -77,11 +75,11 @@ def __repr__(self):
7775
)
7876

7977
@property
80-
def _info(self) -> Dict[str, str]:
78+
def _info(self) -> WindowDict:
8179
attrs = {"window_id": self._window_id}
8280

8381
# from https://github.com/serkanyersen/underscore.py
84-
def by(val) -> bool:
82+
def by(val: WindowDict) -> bool:
8583
for key in attrs.keys():
8684
try:
8785
if attrs[key] != val[key]:
@@ -90,16 +88,15 @@ def by(val) -> bool:
9088
return False
9189
return True
9290

93-
# TODO add type hint
94-
target_windows = list(filter(by, self.server._windows))
91+
target_windows = [s for s in self.server._windows if by(s)]
9592
# If a window_shell option was configured which results in
9693
# a short-lived process, the window id is @0. Use that instead of
9794
# self._window_id
9895
if len(target_windows) == 0 and self.server._windows[0]["window_id"] == "@0":
9996
target_windows = self.server._windows
10097
return target_windows[0]
10198

102-
def cmd(self, cmd: str, *args, **kwargs) -> tmux_cmd:
99+
def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> tmux_cmd:
103100
"""Return :meth:`Server.cmd` defaulting ``target_window`` as target.
104101
105102
Send command to tmux with :attr:`window_id` as ``target-window``.
@@ -217,25 +214,28 @@ def show_window_options(self, g: Optional[bool] = False) -> WindowOptionDict:
217214
-------
218215
dict
219216
"""
220-
221-
tmux_args = tuple()
217+
tmux_args: t.Tuple[str, ...] = tuple()
222218

223219
if g:
224220
tmux_args += ("-g",)
225221

226222
tmux_args += ("show-window-options",)
227-
cmd = self.cmd(*tmux_args).stdout
223+
cmd = self.cmd(*tmux_args)
224+
225+
output = cmd.stdout
228226

229227
# The shlex.split function splits the args at spaces, while also
230228
# retaining quoted sub-strings.
231229
# shlex.split('this is "a test"') => ['this', 'is', 'a test']
232-
cmd = [tuple(shlex.split(item)) for item in cmd]
233230

234-
window_options: WindowOptionDict = dict(cmd)
231+
window_options: WindowOptionDict = {}
232+
for item in output:
233+
key, val = shlex.split(item)
234+
assert isinstance(key, str)
235+
assert isinstance(val, str)
235236

236-
for key, value in window_options.items():
237-
if value.isdigit():
238-
window_options[key] = int(value)
237+
if isinstance(val, str) and val.isdigit():
238+
window_options[key] = int(val)
239239

240240
return window_options
241241

0 commit comments

Comments
 (0)