88import os
99import shlex
1010import typing as t
11+ from typing import TYPE_CHECKING , Dict , Optional , Union
12+
13+ from libtmux .common import tmux_cmd
14+ from libtmux .pane import Pane
1115
1216from . import exc , formats
1317from .common import (
1620 TmuxRelationalObject ,
1721 handle_option_error ,
1822)
19- from .pane import Pane
2023
2124logger = logging .getLogger (__name__ )
2225
26+ if TYPE_CHECKING :
27+ from libtmux .session import Session
28+
2329
2430class Window (TmuxMappingObject , TmuxRelationalObject ):
2531 """
@@ -46,7 +52,7 @@ class Window(TmuxMappingObject, TmuxRelationalObject):
4652 #: namespace used :class:`~libtmux.common.TmuxMappingObject`
4753 formatter_prefix = "window_"
4854
49- def __init__ (self , session = None , ** kwargs ):
55+ def __init__ (self , session : Optional [ "Session" ] = None , ** kwargs ) -> None :
5056
5157 if not session :
5258 raise ValueError ("Window requires a Session, session=Session" )
@@ -69,7 +75,7 @@ def __repr__(self):
6975 )
7076
7177 @property
72- def _info (self ):
78+ def _info (self ) -> Dict [ str , str ] :
7379 attrs = {"window_id" : self ._window_id }
7480
7581 # from https://github.com/serkanyersen/underscore.py
@@ -91,7 +97,7 @@ def by(val) -> bool:
9197 target_windows = self .server ._windows
9298 return target_windows [0 ]
9399
94- def cmd (self , cmd , * args , ** kwargs ):
100+ def cmd (self , cmd : str , * args , ** kwargs ) -> tmux_cmd :
95101 """Return :meth:`Server.cmd` defaulting ``target_window`` as target.
96102
97103 Send command to tmux with :attr:`window_id` as ``target-window``.
@@ -114,7 +120,7 @@ def cmd(self, cmd, *args, **kwargs):
114120
115121 return self .server .cmd (cmd , * args , ** kwargs )
116122
117- def select_layout (self , layout = None ):
123+ def select_layout (self , layout : Optional [ str ] = None ) -> None :
118124 """Wrapper for ``$ tmux select-layout <layout>``.
119125
120126 Parameters
@@ -153,7 +159,7 @@ def select_layout(self, layout=None):
153159 if proc .stderr :
154160 raise exc .LibTmuxException (proc .stderr )
155161
156- def set_window_option (self , option , value ) :
162+ def set_window_option (self , option : str , value : Union [ int , str ]) -> None :
157163 """
158164 Wrapper for ``$ tmux set-window-option <option> <value>``.
159165
@@ -189,7 +195,9 @@ def set_window_option(self, option, value):
189195 if isinstance (cmd .stderr , list ) and len (cmd .stderr ):
190196 handle_option_error (cmd .stderr [0 ])
191197
192- def show_window_options (self , option = None , g = False ):
198+ def show_window_options (
199+ self , option : Optional [str ] = None , g : bool = False
200+ ) -> Union [str , Dict [str , Union [str , int ]], int , Dict [str , str ]]:
193201 """
194202 Return a dict of options for the window.
195203
@@ -232,7 +240,9 @@ def show_window_options(self, option=None, g=False):
232240
233241 return window_options
234242
235- def show_window_option (self , option , g = False ):
243+ def show_window_option (
244+ self , option : str , g : bool = False
245+ ) -> Optional [Union [str , int ]]:
236246 """
237247 Return a list of options for the window.
238248
@@ -302,7 +312,7 @@ def rename_window(self, new_name: str) -> "Window":
302312
303313 return self
304314
305- def kill_window (self ):
315+ def kill_window (self ) -> None :
306316 """Kill the current :class:`Window` object. ``$ tmux kill-window``."""
307317
308318 proc = self .cmd (
@@ -316,7 +326,7 @@ def kill_window(self):
316326
317327 self .server ._update_windows ()
318328
319- def move_window (self , destination = "" , session = None ):
329+ def move_window (self , destination : str = "" , session : Optional [ str ] = None ) -> None :
320330 """
321331 Move the current :class:`Window` object ``$ tmux move-window``.
322332
@@ -385,12 +395,12 @@ def last_pane(self) -> t.Optional[Pane]:
385395
386396 def split_window (
387397 self ,
388- target = None ,
389- start_directory = None ,
390- attach = True ,
391- vertical = True ,
392- shell = None ,
393- percent = None ,
398+ target : None = None ,
399+ start_directory : None = None ,
400+ attach : bool = True ,
401+ vertical : bool = True ,
402+ shell : Optional [ str ] = None ,
403+ percent : None = None ,
394404 ) -> Pane :
395405 """
396406 Split window and return the created :class:`Pane`.
0 commit comments