Skip to content

Commit bce5da6

Browse files
committed
!squash
1 parent 8a3fa85 commit bce5da6

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

libtmux/session.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import logging
88
import os
99
import typing as t
10+
from typing import Any, Dict, List, Optional, Union
11+
12+
from libtmux.common import tmux_cmd
13+
from libtmux.window import Window
1014

1115
from . import exc, formats
1216
from .common import (
@@ -24,6 +28,7 @@
2428

2529
if t.TYPE_CHECKING:
2630
from .pane import Pane
31+
from .server import Server
2732

2833

2934
class Session(TmuxMappingObject, TmuxRelationalObject, EnvironmentMixin):
@@ -54,7 +59,7 @@ class Session(TmuxMappingObject, TmuxRelationalObject, EnvironmentMixin):
5459
#: namespace used :class:`~libtmux.common.TmuxMappingObject`
5560
formatter_prefix = "session_"
5661

57-
def __init__(self, server=None, **kwargs):
62+
def __init__(self, server: Optional["Server"] = None, **kwargs) -> None:
5863
EnvironmentMixin.__init__(self)
5964
self.server = server
6065

@@ -64,7 +69,7 @@ def __init__(self, server=None, **kwargs):
6469
self.server._update_windows()
6570

6671
@property
67-
def _info(self):
72+
def _info(self) -> Dict[str, str]:
6873

6974
attrs = {"session_id": str(self._session_id)}
7075

@@ -84,7 +89,7 @@ def by(val) -> bool:
8489
except IndexError as e:
8590
logger.error(e)
8691

87-
def cmd(self, *args, **kwargs):
92+
def cmd(self, *args, **kwargs) -> tmux_cmd:
8893
"""
8994
Return :meth:`server.cmd`.
9095
@@ -173,11 +178,11 @@ def rename_session(self, new_name: str) -> "Session":
173178

174179
def new_window(
175180
self,
176-
window_name=None,
177-
start_directory=None,
178-
attach=True,
179-
window_index="",
180-
window_shell=None,
181+
window_name: Optional[str] = None,
182+
start_directory: None = None,
183+
attach: bool = True,
184+
window_index: str = "",
185+
window_shell: None = None,
181186
) -> Window:
182187
"""
183188
Return :class:`Window` from ``$ tmux new-window``.
@@ -255,7 +260,7 @@ def new_window(
255260

256261
return window
257262

258-
def kill_window(self, target_window=None):
263+
def kill_window(self, target_window: Optional[str] = None) -> None:
259264
"""Close a tmux window, and all panes inside it, ``$ tmux kill-window``
260265
261266
Kill the current window or the window at ``target-window``. removing it
@@ -374,7 +379,9 @@ def attached_pane(self) -> t.Optional["Pane"]:
374379

375380
return self.attached_window.attached_pane
376381

377-
def set_option(self, option, value, _global=False):
382+
def set_option(
383+
self, option: str, value: Union[int, str], _global: bool = False
384+
) -> None:
378385
"""
379386
Set option ``$ tmux set-option <option> <value>``.
380387
@@ -417,7 +424,9 @@ def set_option(self, option, value, _global=False):
417424
if isinstance(proc.stderr, list) and len(proc.stderr):
418425
handle_option_error(proc.stderr[0])
419426

420-
def show_options(self, option=None, _global=False):
427+
def show_options(
428+
self, option: Optional[str] = None, _global: bool = False
429+
) -> Union[int, Dict[str, str], Dict[str, Union[str, int]]]:
421430
"""
422431
Return a dict of options for the window.
423432
@@ -462,7 +471,7 @@ def show_options(self, option=None, _global=False):
462471

463472
return session_options
464473

465-
def show_option(self, option, _global=False):
474+
def show_option(self, option: str, _global: bool = False) -> Optional[int]:
466475
"""Return a list of options for the window.
467476
468477
Parameters

libtmux/test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Callable, Optional
99

1010
from .exc import WaitTimeout
11+
from libtmux.server import Server
1112

1213
logger = logging.getLogger(__name__)
1314

@@ -17,13 +18,13 @@
1718

1819

1920
class RandomStrSequence:
20-
def __init__(self, characters: str = "abcdefghijklmnopqrstuvwxyz0123456789_"):
21+
def __init__(self, characters: str = "abcdefghijklmnopqrstuvwxyz0123456789_") -> None:
2122
self.characters: str = characters
2223

2324
def __iter__(self):
2425
return self
2526

26-
def __next__(self):
27+
def __next__(self) -> str:
2728
return "".join(random.sample(self.characters, k=8))
2829

2930

@@ -119,7 +120,7 @@ def retry_until(
119120
return True
120121

121122

122-
def get_test_session_name(server, prefix=TEST_SESSION_PREFIX):
123+
def get_test_session_name(server: Server, prefix: str=TEST_SESSION_PREFIX) -> str:
123124
"""
124125
Faker to create a session name that doesn't exist.
125126

0 commit comments

Comments
 (0)