Skip to content

Commit 8038abd

Browse files
authored
pyupgrade (#357)
pip install pyupgrade autoflake; \ pyupgrade --py37 tests/**/*.py docs/**/*.py libtmux/**/*.py; \ poetry run autoflake tests/**/*.py docs/**/*.py libtmux/**/*.py -i --ignore-init-module-imports --exclude libtmux/_compat.py; \ make black isort
1 parent ae6e07f commit 8038abd

File tree

11 files changed

+40
-60
lines changed

11 files changed

+40
-60
lines changed

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ def linkcode_resolve(domain, info): # NOQA: C901
187187
fn = relpath(fn, start=dirname(libtmux.__file__))
188188

189189
if "dev" in about["__version__"]:
190-
return "%s/blob/master/%s/%s%s" % (
190+
return "{}/blob/master/{}/{}{}".format(
191191
about["__github__"],
192192
about["__package_name__"],
193193
fn,
194194
linespec,
195195
)
196196
else:
197-
return "%s/blob/v%s/%s/%s%s" % (
197+
return "{}/blob/v{}/{}/{}{}".format(
198198
about["__github__"],
199199
about["__version__"],
200200
about["__package_name__"],

libtmux/_compat.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf8 -*-
21
# flake8: NOQA
32
import sys
43
from collections.abc import MutableMapping

libtmux/common.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
~~~~~~~~~~~~~~
66
77
"""
8-
import collections
98
import logging
109
import os
1110
import re
@@ -26,7 +25,7 @@
2625
TMUX_MAX_VERSION = "2.4"
2726

2827

29-
class EnvironmentMixin(object):
28+
class EnvironmentMixin:
3029

3130
"""
3231
Mixin class for managing session and server level environment variables in
@@ -142,7 +141,7 @@ def show_environment(self, name=None):
142141
return vars_dict
143142

144143

145-
class tmux_cmd(object):
144+
class tmux_cmd:
146145

147146
"""
148147
:term:`tmux(1)` command via :py:mod:`subprocess`.
@@ -207,7 +206,7 @@ def __init__(self, *args, **kwargs):
207206
stdout, stderr = self.process.communicate()
208207
returncode = self.process.returncode
209208
except Exception as e:
210-
logger.error("Exception for %s: \n%s" % (subprocess.list2cmdline(cmd), e))
209+
logger.error(f"Exception for {subprocess.list2cmdline(cmd)}: \n{e}")
211210

212211
self.returncode = returncode
213212

@@ -223,7 +222,7 @@ def __init__(self, *args, **kwargs):
223222
if not self.stdout:
224223
self.stdout = self.stderr[0]
225224

226-
logger.debug("self.stdout for %s: \n%s" % (" ".join(cmd), self.stdout))
225+
logger.debug("self.stdout for {}: \n{}".format(" ".join(cmd), self.stdout))
227226

228227

229228
class TmuxMappingObject(MutableMapping):
@@ -272,10 +271,10 @@ def __getattr__(self, key):
272271
try:
273272
return self._info[self.formatter_prefix + key]
274273
except KeyError:
275-
raise AttributeError("%s has no property %s" % (self.__class__, key))
274+
raise AttributeError(f"{self.__class__} has no property {key}")
276275

277276

278-
class TmuxRelationalObject(object):
277+
class TmuxRelationalObject:
279278

280279
"""Base Class for managing tmux object child entities. .. # NOQA
281280
@@ -428,8 +427,8 @@ def _is_executable_file_or_link(exe):
428427
if _is_executable_file_or_link(full_path):
429428
return full_path
430429
logger.info(
431-
"'{0}' could not be found in the following search path: "
432-
"'{1}'".format(exe, search_path)
430+
"'{}' could not be found in the following search path: "
431+
"'{}'".format(exe, search_path)
433432
)
434433

435434
return None

libtmux/exc.py

-16
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,37 @@ class TmuxSessionExists(LibTmuxException):
1515

1616
"""Session does not exist in the server."""
1717

18-
pass
19-
2018

2119
class TmuxCommandNotFound(LibTmuxException):
2220

2321
"""Application binary for tmux not found."""
2422

25-
pass
26-
2723

2824
class VersionTooLow(LibTmuxException):
2925

3026
"""Raised if tmux below the minimum version to use libtmux."""
3127

32-
pass
33-
3428

3529
class BadSessionName(LibTmuxException):
3630

3731
"""Disallowed session name for tmux (empty, contains periods or colons)."""
3832

39-
pass
40-
4133

4234
class OptionError(LibTmuxException):
4335

4436
"""Root error for any error involving invalid, ambiguous or bad options."""
4537

46-
pass
47-
4838

4939
class UnknownOption(OptionError):
5040

5141
"""Option unknown to tmux show-option(s) or show-window-option(s)."""
5242

53-
pass
54-
5543

5644
class InvalidOption(OptionError):
5745

5846
"""Option invalid to tmux, introduced in tmux v2.4."""
5947

60-
pass
61-
6248

6349
class AmbiguousOption(OptionError):
6450

6551
"""Option that could potentially match more than one."""
66-
67-
pass

libtmux/pane.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,6 @@ def select_pane(self):
276276
return self.window.select_pane(self.get("pane_id"))
277277

278278
def __repr__(self):
279-
return "%s(%s %s)" % (self.__class__.__name__, self.get("pane_id"), self.window)
279+
return "{}({} {})".format(
280+
self.__class__.__name__, self.get("pane_id"), self.window
281+
)

libtmux/server.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(
7575
socket_path=None,
7676
config_file=None,
7777
colors=None,
78-
**kwargs
78+
**kwargs,
7979
):
8080
EnvironmentMixin.__init__(self, "-g")
8181
self._windows = []
@@ -110,11 +110,11 @@ def cmd(self, *args, **kwargs):
110110

111111
args = list(args)
112112
if self.socket_name:
113-
args.insert(0, "-L{}".format(self.socket_name))
113+
args.insert(0, f"-L{self.socket_name}")
114114
if self.socket_path:
115-
args.insert(0, "-S{}".format(self.socket_path))
115+
args.insert(0, f"-S{self.socket_path}")
116116
if self.config_file:
117-
args.insert(0, "-f{}".format(self.config_file))
117+
args.insert(0, f"-f{self.config_file}")
118118
if self.colors:
119119
if self.colors == 256:
120120
args.insert(0, "-2")
@@ -160,9 +160,7 @@ def _list_sessions(self):
160160
]
161161

162162
# clear up empty dict
163-
sessions = [
164-
dict((k, v) for k, v in session.items() if v) for session in sessions
165-
]
163+
sessions = [{k: v for k, v in session.items() if v} for session in sessions]
166164

167165
return sessions
168166

@@ -228,7 +226,7 @@ def _list_windows(self):
228226
]
229227

230228
# clear up empty dict
231-
windows = [dict((k, v) for k, v in window.items() if v) for window in windows]
229+
windows = [{k: v for k, v in window.items() if v} for window in windows]
232230

233231
# tmux < 1.8 doesn't have window_id, use window_name
234232
for w in windows:
@@ -299,9 +297,9 @@ def _list_panes(self):
299297

300298
# clear up empty dict
301299
panes = [
302-
dict(
303-
(k, v) for k, v in window.items() if v or k == "pane_current_path"
304-
) # preserve pane_current_path, in case it entered a new process
300+
{
301+
k: v for k, v in window.items() if v or k == "pane_current_path"
302+
} # preserve pane_current_path, in case it entered a new process
305303
# where we may not get a cwd from.
306304
for window in panes
307305
]
@@ -372,7 +370,7 @@ def has_session(self, target_session, exact=True):
372370
session_check_name(target_session)
373371

374372
if exact and has_gte_version("2.1"):
375-
target_session = "={}".format(target_session)
373+
target_session = f"={target_session}"
376374

377375
proc = self.cmd("has-session", "-t%s" % target_session)
378376

@@ -464,7 +462,7 @@ def new_session(
464462
window_name=None,
465463
window_command=None,
466464
*args,
467-
**kwargs
465+
**kwargs,
468466
):
469467
"""
470468
Return :class:`Session` from ``$ tmux new-session``.
@@ -570,7 +568,7 @@ def new_session(
570568
session = dict(zip(sformats, session.split(formats.FORMAT_SEPARATOR)))
571569

572570
# clear up empty dict
573-
session = dict((k, v) for k, v in session.items() if v)
571+
session = {k: v for k, v in session.items() if v}
574572

575573
session = Session(server=self, **session)
576574

libtmux/session.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def rename_session(self, new_name):
159159
- https://www.mail-archive.com/[email protected]/msg45186.html
160160
- https://marc.info/?l=openbsd-cvs&m=152183263526828&w=2
161161
"""
162-
pass
163162
else:
164163
raise exc.LibTmuxException(proc.stderr)
165164

@@ -242,7 +241,7 @@ def new_window(
242241
window = dict(zip(wformats, window.split(formats.FORMAT_SEPARATOR)))
243242

244243
# clear up empty dict
245-
window = dict((k, v) for k, v in window.items() if v)
244+
window = {k: v for k, v in window.items() if v}
246245
window = Window(session=self, **window)
247246

248247
self.server._update_windows()
@@ -358,7 +357,7 @@ def select_window(self, target_window):
358357
# Note that we also provide the session ID here, since cmd()
359358
# will not automatically add it as there is already a '-t'
360359
# argument provided.
361-
target = "-t%s:%s" % (self._session_id, target_window)
360+
target = f"-t{self._session_id}:{target_window}"
362361

363362
proc = self.cmd("select-window", target)
364363

@@ -511,4 +510,4 @@ def show_option(self, option, _global=False):
511510
return option[1]
512511

513512
def __repr__(self):
514-
return "%s(%s %s)" % (self.__class__.__name__, self.id, self.name)
513+
return f"{self.__class__.__name__}({self.id} {self.name})"

libtmux/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def temp_window(session, *args, **kwargs):
194194
return
195195

196196

197-
class EnvironmentVarGuard(object):
197+
class EnvironmentVarGuard:
198198

199199
"""Mock environmental variables safetly.
200200

libtmux/window.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, session=None, **kwargs):
5454
self._window_id = kwargs["window_id"]
5555

5656
def __repr__(self):
57-
return "%s(%s %s:%s, %s)" % (
57+
return "{}({} {}:{}, {})".format(
5858
self.__class__.__name__,
5959
self.id,
6060
self.index,
@@ -137,7 +137,7 @@ def select_layout(self, layout=None):
137137
'custom'
138138
custom dimensions (see :term:`tmux(1)` manpages).
139139
"""
140-
cmd = ["select-layout", "-t%s:%s" % (self.get("session_id"), self.index)]
140+
cmd = ["select-layout", "-t{}:{}".format(self.get("session_id"), self.index)]
141141

142142
if layout: # tmux allows select-layout without args
143143
cmd.append(layout)
@@ -174,7 +174,7 @@ def set_window_option(self, option, value):
174174

175175
cmd = self.cmd(
176176
"set-window-option",
177-
"-t%s:%s" % (self.get("session_id"), self.index),
177+
"-t{}:{}".format(self.get("session_id"), self.index),
178178
# '-t%s' % self.id,
179179
option,
180180
value,
@@ -302,7 +302,7 @@ def kill_window(self):
302302
proc = self.cmd(
303303
"kill-window",
304304
# '-t:%s' % self.id
305-
"-t%s:%s" % (self.get("session_id"), self.index),
305+
"-t{}:{}".format(self.get("session_id"), self.index),
306306
)
307307

308308
if proc.stderr:
@@ -326,8 +326,8 @@ def move_window(self, destination="", session=None):
326326
session = session or self.get("session_id")
327327
proc = self.cmd(
328328
"move-window",
329-
"-s%s:%s" % (self.get("session_id"), self.index),
330-
"-t%s:%s" % (session, destination),
329+
"-s{}:{}".format(self.get("session_id"), self.index),
330+
f"-t{session}:{destination}",
331331
)
332332

333333
if proc.stderr:
@@ -481,7 +481,7 @@ def split_window(
481481
pane = dict(zip(pformats, pane.split(formats.FORMAT_SEPARATOR)))
482482

483483
# clear up empty dict
484-
pane = dict((k, v) for k, v in pane.items() if v)
484+
pane = {k: v for k, v in pane.items() if v}
485485

486486
return Pane(window=self, **pane)
487487

tests/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def session(request, server):
7979
"""
8080
try:
8181
server.switch_client(session.get("session_id"))
82-
pass
8382
except exc.LibTmuxException:
8483
# server.attach_session(session.get('session_id'))
8584
pass

tests/test_common.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
def test_allows_master_version(monkeypatch):
3131
def mock_tmux_cmd(param):
32-
class Hi(object):
32+
class Hi:
3333
stdout = ["tmux master"]
3434
stderr = None
3535

@@ -47,7 +47,7 @@ class Hi(object):
4747

4848
def test_allows_next_version(monkeypatch):
4949
def mock_tmux_cmd(param):
50-
class Hi(object):
50+
class Hi:
5151
stdout = ["tmux next-2.9"]
5252
stderr = None
5353

@@ -63,7 +63,7 @@ class Hi(object):
6363

6464
def test_get_version_openbsd(monkeypatch):
6565
def mock_tmux_cmd(param):
66-
class Hi(object):
66+
class Hi:
6767
stderr = ["tmux: unknown option -- V"]
6868

6969
return Hi()
@@ -80,7 +80,7 @@ class Hi(object):
8080

8181
def test_get_version_too_low(monkeypatch):
8282
def mock_tmux_cmd(param):
83-
class Hi(object):
83+
class Hi:
8484
stderr = ["tmux: unknown option -- V"]
8585

8686
return Hi()

0 commit comments

Comments
 (0)