Skip to content

Commit a2b196b

Browse files
committed
!squash flake8
1 parent ce93690 commit a2b196b

File tree

4 files changed

+47
-42
lines changed

4 files changed

+47
-42
lines changed

libtmux/common.py

+30-20
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ def set_environment(self, name: str, value: str) -> None:
8080

8181
args += [name, value]
8282

83-
proc = self.cmd(*args)
83+
cmd = self.cmd(*args)
8484

85-
if proc.stderr:
86-
if isinstance(proc.stderr, list) and len(proc.stderr) == 1:
87-
proc.stderr = proc.stderr[0]
88-
raise ValueError("tmux set-environment stderr: %s" % proc.stderr)
85+
if cmd.stderr:
86+
stderr = (
87+
cmd.stderr[0]
88+
if isinstance(cmd.stderr, list) and len(cmd.stderr) == 1
89+
else cmd.stderr
90+
)
91+
raise ValueError("tmux set-environment stderr: %s" % cmd.stderr)
8992

9093
def unset_environment(self, name: str) -> None:
9194
"""
@@ -101,12 +104,15 @@ def unset_environment(self, name: str) -> None:
101104
args += [self._add_option]
102105
args += ["-u", name]
103106

104-
proc = self.cmd(*args)
107+
cmd = self.cmd(*args)
105108

106-
if proc.stderr:
107-
if isinstance(proc.stderr, list) and len(proc.stderr) == 1:
108-
proc.stderr = proc.stderr[0]
109-
raise ValueError("tmux set-environment stderr: %s" % proc.stderr)
109+
if cmd.stderr:
110+
stderr = (
111+
cmd.stderr[0]
112+
if isinstance(cmd.stderr, list) and len(cmd.stderr) == 1
113+
else cmd.stderr
114+
)
115+
raise ValueError("tmux set-environment stderr: %s" % cmd.stderr)
110116

111117
def remove_environment(self, name: str) -> None:
112118
"""Remove environment variable ``$ tmux set-environment -r <name>``.
@@ -121,12 +127,15 @@ def remove_environment(self, name: str) -> None:
121127
args += [self._add_option]
122128
args += ["-r", name]
123129

124-
proc = self.cmd(*args)
130+
cmd = self.cmd(*args)
125131

126-
if proc.stderr:
127-
if isinstance(proc.stderr, list) and len(proc.stderr) == 1:
128-
proc.stderr = proc.stderr[0]
129-
raise ValueError("tmux set-environment stderr: %s" % proc.stderr)
132+
if cmd.stderr:
133+
stderr = (
134+
cmd.stderr[0]
135+
if isinstance(cmd.stderr, list) and len(cmd.stderr) == 1
136+
else cmd.stderr
137+
)
138+
raise ValueError("tmux set-environment stderr: %s" % cmd.stderr)
130139

131140
def show_environment(self) -> Dict[str, Union[bool, str]]:
132141
"""Show environment ``$ tmux show-environment -t [session]``.
@@ -146,9 +155,10 @@ def show_environment(self) -> Dict[str, Union[bool, str]]:
146155
tmux_args = ["show-environment"]
147156
if self._add_option:
148157
tmux_args += [self._add_option]
149-
vars = self.cmd(*tmux_args).stdout
150-
vars = [tuple(item.split("=", 1)) for item in vars]
151-
vars_dict = {}
158+
cmd = self.cmd(*tmux_args)
159+
output = cmd.stdout
160+
vars = [tuple(item.split("=", 1)) for item in output]
161+
vars_dict: t.Dict[str, t.Union[str, bool]] = {}
152162
for t in vars:
153163
if len(t) == 2:
154164
vars_dict[t[0]] = t[1]
@@ -159,7 +169,7 @@ def show_environment(self) -> Dict[str, Union[bool, str]]:
159169

160170
return vars_dict
161171

162-
def getenv(self, name: str) -> Optional[str]:
172+
def getenv(self, name: str) -> Optional[t.Union[str, bool]]:
163173
"""Show environment variable ``$ tmux show-environment -t [session] <name>``.
164174
165175
Return the value of a specific variable if the name is specified.
@@ -185,7 +195,7 @@ def getenv(self, name: str) -> Optional[str]:
185195
cmd = self.cmd(*tmux_args)
186196
output = cmd.stdout
187197
vars = [tuple(item.split("=", 1)) for item in output]
188-
vars_dict = {}
198+
vars_dict: t.Dict[str, t.Union[str, bool]] = {}
189199
for t in vars:
190200
if len(t) == 2:
191201
vars_dict[t[0]] = t[1]

libtmux/server.py

-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424

2525
logger = logging.getLogger(__name__)
2626

27-
if t.TYPE_CHECKING:
28-
from libtmux.common import SessionDict
29-
from libtmux.window import Window
30-
3127

3228
class Server(TmuxRelationalObject["Session", "SessionDict"], EnvironmentMixin):
3329

libtmux/session.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import logging
88
import os
99
import typing as t
10-
from typing import Dict, Optional, Union
1110

1211
from libtmux.common import tmux_cmd
1312
from libtmux.window import Window
@@ -184,7 +183,7 @@ def rename_session(self, new_name: str) -> "Session":
184183

185184
def new_window(
186185
self,
187-
window_name: Optional[str] = None,
186+
window_name: t.Optional[str] = None,
188187
start_directory: None = None,
189188
attach: bool = True,
190189
window_index: str = "",
@@ -268,7 +267,7 @@ def new_window(
268267

269268
return window
270269

271-
def kill_window(self, target_window: Optional[str] = None) -> None:
270+
def kill_window(self, target_window: t.Optional[str] = None) -> None:
272271
"""Close a tmux window, and all panes inside it, ``$ tmux kill-window``
273272
274273
Kill the current window or the window at ``target-window``. removing it
@@ -388,7 +387,7 @@ def attached_pane(self) -> t.Optional["Pane"]:
388387
return self.attached_window.attached_pane
389388

390389
def set_option(
391-
self, option: str, value: Union[str, int], _global: bool = False
390+
self, option: str, value: t.Union[str, int], _global: bool = False
392391
) -> None:
393392
"""
394393
Set option ``$ tmux set-option <option> <value>``.
@@ -438,8 +437,8 @@ def set_option(
438437
handle_option_error(proc.stderr[0])
439438

440439
def show_options(
441-
self, _global: Optional[bool] = False
442-
) -> t.Dict[str, Union[str, int]]:
440+
self, _global: t.Optional[bool] = False
441+
) -> t.Dict[str, t.Union[str, int]]:
443442
"""
444443
Return a dict of options for the window.
445444
@@ -481,7 +480,7 @@ def show_options(
481480

482481
def show_option(
483482
self, option: str, _global: bool = False
484-
) -> Optional[Union[str, int, bool]]:
483+
) -> t.Optional[t.Union[str, int, bool]]:
485484
"""Return a list of options for the window.
486485
487486
Parameters

libtmux/window.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import os
99
import shlex
1010
import typing as t
11-
from typing import Dict, Optional, Union
1211

1312
from libtmux.common import tmux_cmd
1413
from libtmux.pane import Pane
@@ -24,7 +23,6 @@
2423
)
2524

2625
if t.TYPE_CHECKING:
27-
from .common import PaneDict
2826
from .server import Server
2927
from .session import Session
3028

@@ -122,7 +120,7 @@ def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> tmux_cmd:
122120

123121
return self.server.cmd(cmd, *args, **kwargs)
124122

125-
def select_layout(self, layout: Optional[str] = None) -> None:
123+
def select_layout(self, layout: t.Optional[str] = None) -> None:
126124
"""Wrapper for ``$ tmux select-layout <layout>``.
127125
128126
Parameters
@@ -161,7 +159,7 @@ def select_layout(self, layout: Optional[str] = None) -> None:
161159
if proc.stderr:
162160
raise exc.LibTmuxException(proc.stderr)
163161

164-
def set_window_option(self, option: str, value: Union[int, str]) -> None:
162+
def set_window_option(self, option: str, value: t.Union[int, str]) -> None:
165163
"""
166164
Wrapper for ``$ tmux set-window-option <option> <value>``.
167165
@@ -197,7 +195,7 @@ def set_window_option(self, option: str, value: Union[int, str]) -> None:
197195
if isinstance(cmd.stderr, list) and len(cmd.stderr):
198196
handle_option_error(cmd.stderr[0])
199197

200-
def show_window_options(self, g: Optional[bool] = False) -> WindowOptionDict:
198+
def show_window_options(self, g: t.Optional[bool] = False) -> WindowOptionDict:
201199
"""
202200
Return a dict of options for the window.
203201
@@ -244,7 +242,7 @@ def show_window_options(self, g: Optional[bool] = False) -> WindowOptionDict:
244242

245243
def show_window_option(
246244
self, option: str, g: bool = False
247-
) -> Optional[Union[str, int]]:
245+
) -> t.Optional[t.Union[str, int]]:
248246
"""
249247
Return a list of options for the window.
250248
@@ -330,7 +328,9 @@ def kill_window(self) -> None:
330328

331329
self.server._update_windows()
332330

333-
def move_window(self, destination: str = "", session: Optional[str] = None) -> None:
331+
def move_window(
332+
self, destination: str = "", session: t.Optional[str] = None
333+
) -> None:
334334
"""
335335
Move the current :class:`Window` object ``$ tmux move-window``.
336336
@@ -399,12 +399,12 @@ def last_pane(self) -> t.Optional[Pane]:
399399

400400
def split_window(
401401
self,
402-
target: Optional[t.Union[int, str]] = None,
403-
start_directory: Optional[str] = None,
402+
target: t.Optional[t.Union[int, str]] = None,
403+
start_directory: t.Optional[str] = None,
404404
attach: bool = True,
405405
vertical: bool = True,
406-
shell: Optional[str] = None,
407-
percent: Optional[int] = None,
406+
shell: t.Optional[str] = None,
407+
percent: t.Optional[int] = None,
408408
) -> Pane:
409409
"""
410410
Split window and return the created :class:`Pane`.

0 commit comments

Comments
 (0)