Skip to content

Commit c4aadb7

Browse files
committed
ci(ruff): Automated lint fixes
1 parent 9312060 commit c4aadb7

15 files changed

+41
-63
lines changed

conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import typing as t
1313

1414
import pytest
15-
1615
from _pytest.doctest import DoctestItem
1716

1817
from libtmux.pytest_plugin import USING_ZSH

docs/conf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from pathlib import Path
66
import typing as t
77

8-
import libtmux # NOQA
9-
from libtmux import test # NOQA
8+
import libtmux
9+
from libtmux import test
1010

1111
if t.TYPE_CHECKING:
1212
from sphinx.application import Sphinx
@@ -167,7 +167,7 @@
167167

168168
def linkcode_resolve(
169169
domain: str, info: t.Dict[str, str]
170-
) -> t.Union[None, str]: # NOQA: C901
170+
) -> t.Union[None, str]:
171171
"""
172172
Determine the URL corresponding to Python object
173173

src/libtmux/_internal/query_list.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def lookup_icontains(
123123
if isinstance(data, str):
124124
return rhs.lower() in data.lower()
125125
if isinstance(data, Mapping):
126-
return rhs.lower() in [k.lower() for k in data.keys()]
126+
return rhs.lower() in [k.lower() for k in data]
127127

128128
return False
129129

@@ -183,7 +183,6 @@ def lookup_in(
183183
return rhs in data
184184
# TODO: Add a deep Mappingionary matcher
185185
# if isinstance(rhs, Mapping) and isinstance(data, Mapping):
186-
# return rhs.items() not in data.items()
187186
except Exception:
188187
return False
189188
return False
@@ -205,7 +204,6 @@ def lookup_nin(
205204
return rhs not in data
206205
# TODO: Add a deep Mappingionary matcher
207206
# if isinstance(rhs, Mapping) and isinstance(data, Mapping):
208-
# return rhs.items() not in data.items()
209207
except Exception:
210208
return False
211209
return False
@@ -293,10 +291,6 @@ def __eq__(
293291
self,
294292
other: object,
295293
# other: Union[
296-
# "QueryList[T]",
297-
# List[Mapping[str, str]],
298-
# List[Mapping[str, int]],
299-
# List[Mapping[str, Union[str, Mapping[str, Union[List[str], str]]]]],
300294
# ],
301295
) -> bool:
302296
data = other

src/libtmux/formats.py

-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@
4141
]
4242

4343
WINDOW_FORMATS = [
44-
# format_window()
4544
"window_id",
4645
"window_name",
4746
"window_width",
4847
"window_height",
4948
"window_layout",
5049
"window_panes",
51-
# format_winlink()
5250
"window_index",
5351
"window_flags",
5452
"window_active",

src/libtmux/neo.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,13 @@ class Obj:
4040
alternate_saved_x: t.Union[str, None] = None
4141
alternate_saved_y: t.Union[str, None] = None
4242
# See QUIRK_TMUX_3_1_X_0001
43-
# buffer_created: t.Union[str, None] = None
4443
buffer_name: t.Union[str, None] = None
4544
buffer_sample: t.Union[str, None] = None
4645
buffer_size: t.Union[str, None] = None
4746
# See QUIRK_TMUX_3_1_X_0001
48-
# client_activity: t.Union[str, None] = None
4947
client_cell_height: t.Union[str, None] = None
5048
client_cell_width: t.Union[str, None] = None
5149
# See QUIRK_TMUX_3_1_X_0001
52-
# client_created: t.Union[str, None] = None
5350
client_discarded: t.Union[str, None] = None
5451
client_flags: t.Union[str, None] = None
5552
client_height: t.Union[str, None] = None
@@ -182,11 +179,11 @@ def _refresh(
182179

183180

184181
def fetch_objs(
185-
server: "Server", list_cmd: "ListCmd", list_extra_args: "ListExtraArgs" = None
182+
server: "Server", list_cmd: "ListCmd", list_extra_args: "t.Optional[ListExtraArgs]" = None
186183
) -> OutputsRaw:
187184
formats = list(Obj.__dataclass_fields__.keys())
188185

189-
cmd_args: t.List[t.Union[str, int]] = list()
186+
cmd_args: t.List[t.Union[str, int]] = []
190187

191188
if server.socket_name:
192189
cmd_args.insert(0, f"-L{server.socket_name}")
@@ -229,7 +226,7 @@ def fetch_obj(
229226
obj_key: str,
230227
obj_id: str,
231228
list_cmd: "ListCmd" = "list-panes",
232-
list_extra_args: "ListExtraArgs" = None,
229+
list_extra_args: "t.Optional[ListExtraArgs]" = None,
233230
) -> OutputRaw:
234231
obj_formatters_filtered = fetch_objs(
235232
server=server, list_cmd=list_cmd, list_extra_args=list_extra_args

src/libtmux/pytest_plugin.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import getpass
23
import logging
34
import os
@@ -80,7 +81,7 @@ def clear_env(monkeypatch: pytest.MonkeyPatch) -> None:
8081
8182
tmux show-environment tests were being interrupted due to a lot of crazy env vars.
8283
"""
83-
for k, v in os.environ.items():
84+
for k, _v in os.environ.items():
8485
if not any(
8586
needle in k.lower()
8687
for needle in [
@@ -236,16 +237,14 @@ def session(
236237
session_id = session.session_id
237238
assert session_id is not None
238239

239-
try:
240+
with contextlib.suppress(exc.LibTmuxException):
240241
server.switch_client(target_session=session_id)
241-
except exc.LibTmuxException:
242-
# server.attach_session(session.get('session_id'))
243-
pass
242+
244243

245244
for old_test_session in old_test_sessions:
246245
logger.debug(f"Old test test session {old_test_session} found. Killing it.")
247246
server.kill_session(old_test_session)
248-
assert TEST_SESSION_NAME == session.session_name
247+
assert session.session_name == TEST_SESSION_NAME
249248
assert TEST_SESSION_NAME != "tmuxp"
250249

251250
return session

src/libtmux/server.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def raise_if_dead(self) -> None:
169169
if self.config_file:
170170
cmd_args.insert(0, f"-f{self.config_file}")
171171

172-
subprocess.check_call([tmux_bin] + cmd_args)
172+
subprocess.check_call([tmux_bin, *cmd_args])
173173

174174
#
175175
# Command
@@ -227,7 +227,7 @@ def attached_sessions(self) -> t.List[Session]:
227227
"""
228228
try:
229229
sessions = self.sessions
230-
attached_sessions = list()
230+
attached_sessions = []
231231

232232
for session in sessions:
233233
attached = session.session_attached
@@ -239,7 +239,6 @@ def attached_sessions(self) -> t.List[Session]:
239239
continue
240240

241241
return attached_sessions
242-
# return [Session(**s) for s in attached_sessions] or None
243242
except Exception:
244243
return []
245244

@@ -339,7 +338,7 @@ def attach_session(self, target_session: t.Optional[str] = None) -> None:
339338
"""
340339
session_check_name(target_session)
341340

342-
tmux_args: t.Tuple[str, ...] = tuple()
341+
tmux_args: t.Tuple[str, ...] = ()
343342
if target_session:
344343
tmux_args += ("-t%s" % target_session,)
345344

@@ -574,7 +573,7 @@ def __repr__(self) -> str:
574573
elif self.socket_path is not None:
575574
return (
576575
f"{self.__class__.__name__}"
577-
f"(socket_path={getattr(self, 'socket_path')})"
576+
f"(socket_path={self.socket_path})"
578577
)
579578
return f"{self.__class__.__name__}" f"(socket_path=/tmp/tmux-1000/default)"
580579

src/libtmux/session.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def cmd(self, *args: t.Any, **kwargs: t.Any) -> tmux_cmd:
151151
# if -t is not set in any arg yet
152152
if not any("-t" in str(x) for x in args):
153153
# insert -t immediately after 1st arg, as per tmux format
154-
new_args: t.Tuple[str, ...] = tuple()
154+
new_args: t.Tuple[str, ...] = ()
155155
new_args += (args[0],)
156156
assert isinstance(self.session_id, str)
157157
new_args += (
@@ -163,7 +163,6 @@ def cmd(self, *args: t.Any, **kwargs: t.Any) -> tmux_cmd:
163163
return self.server.cmd(*args, **kwargs)
164164

165165
#
166-
# Commands (tmux-like)
167166
#
168167
def set_option(
169168
self, option: str, value: t.Union[str, int], _global: bool = False
@@ -197,7 +196,7 @@ def set_option(
197196
elif isinstance(value, bool) and not value:
198197
value = "off"
199198

200-
tmux_args: t.Tuple[t.Union[str, int], ...] = tuple()
199+
tmux_args: t.Tuple[t.Union[str, int], ...] = ()
201200

202201
if _global:
203202
tmux_args += ("-g",)
@@ -240,7 +239,7 @@ def show_options(
240239
Uses ``_global`` for keyword name instead of ``global`` to avoid
241240
colliding with reserved keyword.
242241
"""
243-
tmux_args: t.Tuple[str, ...] = tuple()
242+
tmux_args: t.Tuple[str, ...] = ()
244243

245244
if _global:
246245
tmux_args += ("-g",)
@@ -288,7 +287,7 @@ def show_option(
288287
Test and return True/False for on/off string.
289288
"""
290289

291-
tmux_args: t.Tuple[str, ...] = tuple()
290+
tmux_args: t.Tuple[str, ...] = ()
292291

293292
if _global:
294293
tmux_args += ("-g",)
@@ -476,7 +475,7 @@ def new_window(
476475
-------
477476
:class:`Window`
478477
"""
479-
window_args: t.Tuple[str, ...] = tuple()
478+
window_args: t.Tuple[str, ...] = ()
480479

481480
if not attach:
482481
window_args += ("-d",)
@@ -494,8 +493,7 @@ def new_window(
494493

495494
window_args += (
496495
# empty string for window_index will use the first one available
497-
"-t%s:%s"
498-
% (self.session_id, window_index),
496+
f"-t{self.session_id}:{window_index}",
499497
)
500498

501499
if environment:

src/libtmux/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class EnvironmentVarGuard:
305305
def __init__(self) -> None:
306306
self._environ = os.environ
307307
self._unset: t.Set[str] = set()
308-
self._reset: t.Dict[str, str] = dict()
308+
self._reset: t.Dict[str, str] = {}
309309

310310
def set(self, envvar: str, value: str) -> None:
311311
if envvar not in self._environ:

src/libtmux/window.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def panes(self) -> QueryList["Pane"]: # type: ignore
125125
return QueryList(panes)
126126

127127
#
128-
# Command (pane-scoped)
129128
#
130129
def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> tmux_cmd:
131130
"""Return :meth:`Server.cmd` defaulting to ``target_window`` as target.
@@ -136,12 +135,11 @@ def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> tmux_cmd:
136135
``args`` will override using the object's ``window_id`` as target.
137136
"""
138137
if not any(arg.startswith("-t") for arg in args):
139-
args = ("-t", self.window_id) + args
138+
args = ("-t", self.window_id, *args)
140139

141140
return self.server.cmd(cmd, *args, **kwargs)
142141

143142
#
144-
# Commands (tmux-like)
145143
#
146144
def select_pane(self, target_pane: t.Union[str, int]) -> t.Optional["Pane"]:
147145
"""
@@ -219,21 +217,18 @@ def split_window(
219217
"""
220218
tmux_formats = ["#{pane_id}" + FORMAT_SEPARATOR]
221219

222-
# '-t%s' % self.attached_pane.get('pane_id'),
223220
# 2013-10-18 LOOK AT THIS, rm'd it..
224-
tmux_args: t.Tuple[str, ...] = tuple()
221+
tmux_args: t.Tuple[str, ...] = ()
225222

226223
if target is not None:
227224
tmux_args += ("-t%s" % target,)
228225
else:
229226
if len(self.panes):
230227
tmux_args += (
231-
"-t%s:%s.%s"
232-
% (self.session_id, self.window_id, self.panes[0].pane_index),
228+
f"-t{self.session_id}:{self.window_id}.{self.panes[0].pane_index}",
233229
)
234230
else:
235-
tmux_args += ("-t%s:%s" % (self.session_id, self.window_id),)
236-
# tmux_args += ("-t%s" % self.panes[0].pane_id,)
231+
tmux_args += (f"-t{self.session_id}:{self.window_id}",)
237232

238233
if vertical:
239234
tmux_args += ("-v",)
@@ -313,7 +308,7 @@ def select_layout(self, layout: t.Optional[str] = None) -> "Window":
313308
'custom'
314309
custom dimensions (see :term:`tmux(1)` manpages).
315310
"""
316-
cmd = ["select-layout", "-t{}:{}".format(self.session_id, self.window_index)]
311+
cmd = ["select-layout", f"-t{self.session_id}:{self.window_index}"]
317312

318313
if layout: # tmux allows select-layout without args
319314
cmd.append(layout)
@@ -349,7 +344,7 @@ def set_window_option(self, option: str, value: t.Union[int, str]) -> "Window":
349344

350345
cmd = self.cmd(
351346
"set-window-option",
352-
"-t{}:{}".format(self.session_id, self.window_index),
347+
f"-t{self.session_id}:{self.window_index}",
353348
option,
354349
value,
355350
)
@@ -375,7 +370,7 @@ def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict"
375370
g : str, optional
376371
Pass ``-g`` flag for global variable, default False.
377372
"""
378-
tmux_args: t.Tuple[str, ...] = tuple()
373+
tmux_args: t.Tuple[str, ...] = ()
379374

380375
if g:
381376
tmux_args += ("-g",)
@@ -419,7 +414,7 @@ def show_window_option(
419414
:exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
420415
:exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
421416
"""
422-
tmux_args: t.Tuple[t.Union[str, int], ...] = tuple()
417+
tmux_args: t.Tuple[t.Union[str, int], ...] = ()
423418

424419
if g:
425420
tmux_args += ("-g",)
@@ -486,7 +481,7 @@ def kill_window(self) -> None:
486481

487482
proc = self.cmd(
488483
"kill-window",
489-
"-t{}:{}".format(self.session_id, self.window_index),
484+
f"-t{self.session_id}:{self.window_index}",
490485
)
491486

492487
if proc.stderr:
@@ -510,7 +505,7 @@ def move_window(
510505
session = session or self.session_id
511506
proc = self.cmd(
512507
"move-window",
513-
"-s{}:{}".format(self.session_id, self.window_index),
508+
f"-s{self.session_id}:{self.window_index}",
514509
f"-t{session}:{destination}",
515510
)
516511

tests/legacy_api/test_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def mock_tmux_cmd(*args: t.Any, **kwargs: t.Any) -> Hi:
6262
assert has_minimum_version()
6363
assert has_gte_version(TMUX_MIN_VERSION)
6464
assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version"
65-
assert TMUX_NEXT_VERSION == get_version()
65+
assert get_version() == TMUX_NEXT_VERSION
6666

6767

6868
def test_get_version_openbsd(monkeypatch: pytest.MonkeyPatch) -> None:

tests/legacy_api/test_server.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ def test_show_environment(server: Server) -> None:
7171
def test_getenv(server: Server, session: Session) -> None:
7272
"""Set environment then Server.show_environment(key)."""
7373
server.set_environment("FOO", "BAR")
74-
assert "BAR" == server.getenv("FOO")
74+
assert server.getenv("FOO") == "BAR"
7575

7676
server.set_environment("FOO", "DAR")
77-
assert "DAR" == server.getenv("FOO")
77+
assert server.getenv("FOO") == "DAR"
7878

79-
assert "DAR" == server.show_environment()["FOO"]
79+
assert server.show_environment()["FOO"] == "DAR"
8080

8181

8282
def test_show_environment_not_set(server: Server) -> None:

0 commit comments

Comments
 (0)