Skip to content

Commit d80eb49

Browse files
committed
Adding type hints to methods returning self and child objects
1 parent 92f430f commit d80eb49

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

libtmux/session.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
"""
77
import logging
88
import os
9+
import typing as t
910

1011
from . import exc, formats
1112
from .common import (
1213
EnvironmentMixin,
1314
TmuxMappingObject,
1415
TmuxRelationalObject,
16+
WindowDict,
1517
handle_option_error,
1618
has_version,
1719
session_check_name,
@@ -129,7 +131,7 @@ def switch_client(self):
129131
if proc.stderr:
130132
raise exc.LibTmuxException(proc.stderr)
131133

132-
def rename_session(self, new_name):
134+
def rename_session(self, new_name: str) -> "Session":
133135
"""
134136
Rename session and return new :class:`Session` object.
135137
@@ -171,7 +173,7 @@ def new_window(
171173
attach=True,
172174
window_index="",
173175
window_shell=None,
174-
):
176+
) -> Window:
175177
"""
176178
Return :class:`Window` from ``$ tmux new-window``.
177179
@@ -273,20 +275,18 @@ def kill_window(self, target_window=None):
273275

274276
self.server._update_windows()
275277

276-
def _list_windows(self):
278+
def _list_windows(self) -> t.List[WindowDict]:
277279
windows = self.server._update_windows()._windows
278280

279-
windows = [w for w in windows if w["session_id"] == self.id]
280-
281-
return windows
281+
return [w for w in windows if w["session_id"] == self.id]
282282

283283
@property
284-
def _windows(self):
284+
def _windows(self) -> t.List[WindowDict]:
285285
"""Property / alias to return :meth:`Session._list_windows`."""
286286

287287
return self._list_windows()
288288

289-
def list_windows(self):
289+
def list_windows(self) -> t.List[Window]:
290290
"""Return a list of :class:`Window` from the ``tmux(1)`` session.
291291
292292
Returns
@@ -298,15 +298,15 @@ def list_windows(self):
298298
return [Window(session=self, **window) for window in windows]
299299

300300
@property
301-
def windows(self):
301+
def windows(self) -> t.List[Window]:
302302
"""Property / alias to return :meth:`Session.list_windows`."""
303303
return self.list_windows()
304304

305305
#: Alias :attr:`windows` for :class:`~libtmux.common.TmuxRelationalObject`
306306
children = windows
307307

308308
@property
309-
def attached_window(self):
309+
def attached_window(self) -> Window:
310310
"""
311311
Return active :class:`Window` object.
312312
@@ -333,7 +333,7 @@ def attached_window(self):
333333
if len(self._windows) == int(0):
334334
raise exc.LibTmuxException("No Windows")
335335

336-
def select_window(self, target_window):
336+
def select_window(self, target_window: str) -> Window:
337337
"""
338338
Return :class:`Window` selected via ``$ tmux select-window``.
339339

0 commit comments

Comments
 (0)