Skip to content

Commit d35d80b

Browse files
committed
ci(ruff): Automated lint fixes
Fixed 81 errors: - conftest.py: 1 × I001 (unsorted-imports) - docs/conf.py: 2 × RUF100 (unused-noqa) 1 × SIM108 (if-else-block-instead-of-if-exp) 1 × I001 (unsorted-imports) - src/libtmux/_internal/query_list.py: 6 × ERA001 (commented-out-code) 1 × SIM118 (in-dict-keys) - src/libtmux/common.py: 1 × UP031 (printf-string-formatting) 1 × C408 (unnecessary-collection-call) - src/libtmux/formats.py: 2 × ERA001 (commented-out-code) - src/libtmux/neo.py: 3 × ERA001 (commented-out-code) 1 × C408 (unnecessary-collection-call) - src/libtmux/pane.py: 4 × ERA001 (commented-out-code) 4 × RUF002 (ambiguous-unicode-character-docstring) 1 × RUF005 (collection-literal-concatenation) 1 × UP032 (f-string) - src/libtmux/pytest_plugin.py: 1 × F841 (unused-variable) 1 × SIM300 (yoda-conditions) 1 × TRY201 (verbose-raise) 1 × ERA001 (commented-out-code) 1 × SIM105 (suppressible-exception) 1 × I001 (unsorted-imports) 1 × SIM118 (in-dict-keys) 1 × PERF102 (incorrect-dict-iterator) - src/libtmux/server.py: 2 × C408 (unnecessary-collection-call) 1 × RUF005 (collection-literal-concatenation) 1 × B009 (get-attr-with-constant) 1 × ERA001 (commented-out-code) - src/libtmux/session.py: 5 × C408 (unnecessary-collection-call) 2 × RUF015 (unnecessary-iterable-allocation-for-first-element) 1 × UP031 (printf-string-formatting) 1 × ERA001 (commented-out-code) 1 × UP032 (f-string) - src/libtmux/test.py: 1 × C408 (unnecessary-collection-call) - src/libtmux/window.py: 6 × UP032 (f-string) 4 × ERA001 (commented-out-code) 3 × C408 (unnecessary-collection-call) 2 × UP031 (printf-string-formatting) 1 × RUF005 (collection-literal-concatenation) 1 × RUF015 (unnecessary-iterable-allocation-for-first-element) - tests/legacy_api/test_common.py: 1 × SIM300 (yoda-conditions) - tests/legacy_api/test_server.py: 3 × SIM300 (yoda-conditions) - tests/test_common.py: 1 × SIM300 (yoda-conditions) - tests/test_pytest_plugin.py: 1 × ERA001 (commented-out-code) 1 × RUF015 (unnecessary-iterable-allocation-for-first-element) - tests/test_server.py: 3 × SIM300 (yoda-conditions)
1 parent 906c038 commit d35d80b

File tree

17 files changed

+59
-92
lines changed

17 files changed

+59
-92
lines changed

conftest.py

Lines changed: 0 additions & 1 deletion
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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# flake8: NOQA: E501
22
import contextlib
33
import inspect
4-
import sys
5-
from os.path import relpath
64
import pathlib
5+
import sys
76
import typing as t
7+
from os.path import relpath
88

9-
import libtmux # NOQA
10-
from libtmux import test # NOQA
9+
import libtmux
1110

1211
if t.TYPE_CHECKING:
1312
from sphinx.application import Sphinx
@@ -166,9 +165,7 @@
166165
}
167166

168167

169-
def linkcode_resolve(
170-
domain: str, info: t.Dict[str, str]
171-
) -> t.Union[None, str]: # NOQA: C901
168+
def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
172169
"""
173170
Determine the URL corresponding to Python object
174171
@@ -216,10 +213,7 @@ def linkcode_resolve(
216213
except Exception:
217214
lineno = None
218215

219-
if lineno:
220-
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
221-
else:
222-
linespec = ""
216+
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) if lineno else ""
223217

224218
fn = relpath(fn, start=pathlib.Path(libtmux.__file__).parent)
225219

src/libtmux/_internal/query_list.py

Lines changed: 1 addition & 7 deletions
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/common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def getenv(self, name: str) -> Optional[t.Union[str, bool]]:
172172
str
173173
Value of environment variable
174174
"""
175-
tmux_args: t.Tuple[t.Union[str, int], ...] = tuple()
175+
tmux_args: t.Tuple[t.Union[str, int], ...] = ()
176176

177177
tmux_args += ("show-environment",)
178178
if self._add_option:
@@ -425,9 +425,10 @@ def has_minimum_version(raises: bool = True) -> bool:
425425
if get_version() < LooseVersion(TMUX_MIN_VERSION):
426426
if raises:
427427
raise exc.VersionTooLow(
428-
"libtmux only supports tmux %s and greater. This system"
429-
" has %s installed. Upgrade your tmux to use libtmux."
430-
% (TMUX_MIN_VERSION, get_version())
428+
"libtmux only supports tmux {} and greater. This system"
429+
" has {} installed. Upgrade your tmux to use libtmux.".format(
430+
TMUX_MIN_VERSION, get_version()
431+
)
431432
)
432433
else:
433434
return False

src/libtmux/formats.py

Lines changed: 0 additions & 2 deletions
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

Lines changed: 5 additions & 6 deletions
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,13 @@ def _refresh(
182179

183180

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

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

191190
if server.socket_name:
192191
cmd_args.insert(0, f"-L{server.socket_name}")
@@ -229,7 +228,7 @@ def fetch_obj(
229228
obj_key: str,
230229
obj_id: str,
231230
list_cmd: "ListCmd" = "list-panes",
232-
list_extra_args: "ListExtraArgs" = None,
231+
list_extra_args: "t.Optional[ListExtraArgs]" = None,
233232
) -> OutputRaw:
234233
obj_formatters_filtered = fetch_objs(
235234
server=server, list_cmd=list_cmd, list_extra_args=list_extra_args

src/libtmux/pane.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def session(self) -> "Session":
103103
return self.window.session
104104

105105
#
106-
# Command (pane-scoped)
107106
#
108107
def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> tmux_cmd:
109108
"""Return :meth:`Server.cmd` defaulting to ``target_pane`` as target.
@@ -114,12 +113,11 @@ def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> tmux_cmd:
114113
``args`` will override using the object's ``pane_id`` as target.
115114
"""
116115
if not any(arg.startswith("-t") for arg in args):
117-
args = ("-t", self.pane_id) + args
116+
args = ("-t", self.pane_id, *args)
118117

119118
return self.server.cmd(cmd, *args, **kwargs)
120119

121120
#
122-
# Commands (tmux-like)
123121
#
124122
def resize_pane(self, *args: t.Any, **kwargs: t.Any) -> "Pane":
125123
"""
@@ -174,14 +172,14 @@ def capture_pane(
174172
Zero is the first line of the visible pane.
175173
Positive numbers are lines in the visible pane.
176174
Negative numbers are lines in the history.
177-
‘-’ is the start of the history.
175+
`-` is the start of the history.
178176
Default: None
179177
end: [str,int]
180178
Specify the ending line number.
181179
Zero is the first line of the visible pane.
182180
Positive numbers are lines in the visible pane.
183181
Negative numbers are lines in the history.
184-
‘-’ is the end of the visible pane
182+
`-` is the end of the visible pane
185183
Default: None
186184
"""
187185
cmd = ["capture-pane", "-p"]
@@ -277,7 +275,6 @@ def display_message(
277275
return None
278276

279277
#
280-
# Commands ("climber"-helpers)
281278
#
282279
# These are commands that climb to the parent scope's methods with
283280
# additional scoped window info.
@@ -326,7 +323,6 @@ def split_window(
326323
)
327324

328325
#
329-
# Commands (helpers)
330326
#
331327
def set_width(self, width: int) -> "Pane":
332328
"""
@@ -380,7 +376,7 @@ def __eq__(self, other: object) -> bool:
380376
return self.pane_id == other.pane_id
381377

382378
def __repr__(self) -> str:
383-
return "{}({} {})".format(self.__class__.__name__, self.pane_id, self.window)
379+
return f"{self.__class__.__name__}({self.pane_id} {self.window})"
384380

385381
#
386382
# Aliases

src/libtmux/pytest_plugin.py

Lines changed: 6 additions & 8 deletions
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 in os.environ:
8485
if not any(
8586
needle in k.lower()
8687
for needle in [
@@ -226,8 +227,8 @@ def session(
226227

227228
try:
228229
session = server.new_session(session_name=TEST_SESSION_NAME, **session_params)
229-
except exc.LibTmuxException as e:
230-
raise e
230+
except exc.LibTmuxException:
231+
raise
231232

232233
"""
233234
Make sure that tmuxp can :ref:`test_builder_visually` and switches to
@@ -236,16 +237,13 @@ 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
244242

245243
for old_test_session in old_test_sessions:
246244
logger.debug(f"Old test test session {old_test_session} found. Killing it.")
247245
server.kill_session(old_test_session)
248-
assert TEST_SESSION_NAME == session.session_name
246+
assert session.session_name == TEST_SESSION_NAME
249247
assert TEST_SESSION_NAME != "tmuxp"
250248

251249
return session

src/libtmux/server.py

Lines changed: 4 additions & 8 deletions
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

@@ -572,10 +571,7 @@ def __repr__(self) -> str:
572571
f"(socket_name={getattr(self, 'socket_name', 'default')})"
573572
)
574573
elif self.socket_path is not None:
575-
return (
576-
f"{self.__class__.__name__}"
577-
f"(socket_path={getattr(self, 'socket_path')})"
578-
)
574+
return f"{self.__class__.__name__}" f"(socket_path={self.socket_path})"
579575
return f"{self.__class__.__name__}" f"(socket_path=/tmp/tmux-1000/default)"
580576

581577
#

src/libtmux/session.py

Lines changed: 8 additions & 10 deletions
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",)
@@ -303,7 +302,7 @@ def show_option(
303302
if not len(cmd.stdout):
304303
return None
305304

306-
value_raw: t.List[str] = [item.split(" ") for item in cmd.stdout][0]
305+
value_raw: t.List[str] = next(item.split(" ") for item in cmd.stdout)
307306

308307
assert isinstance(value_raw[0], str)
309308
assert isinstance(value_raw[1], str)
@@ -362,7 +361,7 @@ def attached_window(self) -> "Window":
362361
active_windows.append(window)
363362

364363
if len(active_windows) == 1:
365-
return list(active_windows)[0]
364+
return next(iter(active_windows))
366365
elif len(active_windows) == 0:
367366
raise exc.LibTmuxException("no active windows found")
368367
else:
@@ -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:

0 commit comments

Comments
 (0)