Skip to content

pyupgrade @ 3.7 #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ def linkcode_resolve(domain, info): # NOQA: C901
fn = relpath(fn, start=dirname(libtmux.__file__))

if "dev" in about["__version__"]:
return "%s/blob/master/%s/%s%s" % (
return "{}/blob/master/{}/{}{}".format(
about["__github__"],
about["__package_name__"],
fn,
linespec,
)
else:
return "%s/blob/v%s/%s/%s%s" % (
return "{}/blob/v{}/{}/{}{}".format(
about["__github__"],
about["__version__"],
about["__package_name__"],
Expand Down
1 change: 0 additions & 1 deletion libtmux/_compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf8 -*-
# flake8: NOQA
import sys
from collections.abc import MutableMapping
Expand Down
17 changes: 8 additions & 9 deletions libtmux/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
~~~~~~~~~~~~~~

"""
import collections
import logging
import os
import re
Expand All @@ -26,7 +25,7 @@
TMUX_MAX_VERSION = "2.4"


class EnvironmentMixin(object):
class EnvironmentMixin:

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


class tmux_cmd(object):
class tmux_cmd:

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

self.returncode = returncode

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

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


class TmuxMappingObject(MutableMapping):
Expand Down Expand Up @@ -272,10 +271,10 @@ def __getattr__(self, key):
try:
return self._info[self.formatter_prefix + key]
except KeyError:
raise AttributeError("%s has no property %s" % (self.__class__, key))
raise AttributeError(f"{self.__class__} has no property {key}")


class TmuxRelationalObject(object):
class TmuxRelationalObject:

"""Base Class for managing tmux object child entities. .. # NOQA

Expand Down Expand Up @@ -428,8 +427,8 @@ def _is_executable_file_or_link(exe):
if _is_executable_file_or_link(full_path):
return full_path
logger.info(
"'{0}' could not be found in the following search path: "
"'{1}'".format(exe, search_path)
"'{}' could not be found in the following search path: "
"'{}'".format(exe, search_path)
)

return None
Expand Down
16 changes: 0 additions & 16 deletions libtmux/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,37 @@ class TmuxSessionExists(LibTmuxException):

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

pass


class TmuxCommandNotFound(LibTmuxException):

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

pass


class VersionTooLow(LibTmuxException):

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

pass


class BadSessionName(LibTmuxException):

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

pass


class OptionError(LibTmuxException):

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

pass


class UnknownOption(OptionError):

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

pass


class InvalidOption(OptionError):

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

pass


class AmbiguousOption(OptionError):

"""Option that could potentially match more than one."""

pass
4 changes: 3 additions & 1 deletion libtmux/pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,6 @@ def select_pane(self):
return self.window.select_pane(self.get("pane_id"))

def __repr__(self):
return "%s(%s %s)" % (self.__class__.__name__, self.get("pane_id"), self.window)
return "{}({} {})".format(
self.__class__.__name__, self.get("pane_id"), self.window
)
26 changes: 12 additions & 14 deletions libtmux/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(
socket_path=None,
config_file=None,
colors=None,
**kwargs
**kwargs,
):
EnvironmentMixin.__init__(self, "-g")
self._windows = []
Expand Down Expand Up @@ -110,11 +110,11 @@ def cmd(self, *args, **kwargs):

args = list(args)
if self.socket_name:
args.insert(0, "-L{}".format(self.socket_name))
args.insert(0, f"-L{self.socket_name}")
if self.socket_path:
args.insert(0, "-S{}".format(self.socket_path))
args.insert(0, f"-S{self.socket_path}")
if self.config_file:
args.insert(0, "-f{}".format(self.config_file))
args.insert(0, f"-f{self.config_file}")
if self.colors:
if self.colors == 256:
args.insert(0, "-2")
Expand Down Expand Up @@ -160,9 +160,7 @@ def _list_sessions(self):
]

# clear up empty dict
sessions = [
dict((k, v) for k, v in session.items() if v) for session in sessions
]
sessions = [{k: v for k, v in session.items() if v} for session in sessions]

return sessions

Expand Down Expand Up @@ -228,7 +226,7 @@ def _list_windows(self):
]

# clear up empty dict
windows = [dict((k, v) for k, v in window.items() if v) for window in windows]
windows = [{k: v for k, v in window.items() if v} for window in windows]

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

# clear up empty dict
panes = [
dict(
(k, v) for k, v in window.items() if v or k == "pane_current_path"
) # preserve pane_current_path, in case it entered a new process
{
k: v for k, v in window.items() if v or k == "pane_current_path"
} # preserve pane_current_path, in case it entered a new process
# where we may not get a cwd from.
for window in panes
]
Expand Down Expand Up @@ -372,7 +370,7 @@ def has_session(self, target_session, exact=True):
session_check_name(target_session)

if exact and has_gte_version("2.1"):
target_session = "={}".format(target_session)
target_session = f"={target_session}"

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

Expand Down Expand Up @@ -464,7 +462,7 @@ def new_session(
window_name=None,
window_command=None,
*args,
**kwargs
**kwargs,
):
"""
Return :class:`Session` from ``$ tmux new-session``.
Expand Down Expand Up @@ -570,7 +568,7 @@ def new_session(
session = dict(zip(sformats, session.split(formats.FORMAT_SEPARATOR)))

# clear up empty dict
session = dict((k, v) for k, v in session.items() if v)
session = {k: v for k, v in session.items() if v}

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

Expand Down
7 changes: 3 additions & 4 deletions libtmux/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def rename_session(self, new_name):
- https://www.mail-archive.com/[email protected]/msg45186.html
- https://marc.info/?l=openbsd-cvs&m=152183263526828&w=2
"""
pass
else:
raise exc.LibTmuxException(proc.stderr)

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

# clear up empty dict
window = dict((k, v) for k, v in window.items() if v)
window = {k: v for k, v in window.items() if v}
window = Window(session=self, **window)

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

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

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

def __repr__(self):
return "%s(%s %s)" % (self.__class__.__name__, self.id, self.name)
return f"{self.__class__.__name__}({self.id} {self.name})"
2 changes: 1 addition & 1 deletion libtmux/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def temp_window(session, *args, **kwargs):
return


class EnvironmentVarGuard(object):
class EnvironmentVarGuard:

"""Mock environmental variables safetly.

Expand Down
14 changes: 7 additions & 7 deletions libtmux/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, session=None, **kwargs):
self._window_id = kwargs["window_id"]

def __repr__(self):
return "%s(%s %s:%s, %s)" % (
return "{}({} {}:{}, {})".format(
self.__class__.__name__,
self.id,
self.index,
Expand Down Expand Up @@ -137,7 +137,7 @@ def select_layout(self, layout=None):
'custom'
custom dimensions (see :term:`tmux(1)` manpages).
"""
cmd = ["select-layout", "-t%s:%s" % (self.get("session_id"), self.index)]
cmd = ["select-layout", "-t{}:{}".format(self.get("session_id"), self.index)]

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

cmd = self.cmd(
"set-window-option",
"-t%s:%s" % (self.get("session_id"), self.index),
"-t{}:{}".format(self.get("session_id"), self.index),
# '-t%s' % self.id,
option,
value,
Expand Down Expand Up @@ -302,7 +302,7 @@ def kill_window(self):
proc = self.cmd(
"kill-window",
# '-t:%s' % self.id
"-t%s:%s" % (self.get("session_id"), self.index),
"-t{}:{}".format(self.get("session_id"), self.index),
)

if proc.stderr:
Expand All @@ -326,8 +326,8 @@ def move_window(self, destination="", session=None):
session = session or self.get("session_id")
proc = self.cmd(
"move-window",
"-s%s:%s" % (self.get("session_id"), self.index),
"-t%s:%s" % (session, destination),
"-s{}:{}".format(self.get("session_id"), self.index),
f"-t{session}:{destination}",
)

if proc.stderr:
Expand Down Expand Up @@ -481,7 +481,7 @@ def split_window(
pane = dict(zip(pformats, pane.split(formats.FORMAT_SEPARATOR)))

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

return Pane(window=self, **pane)

Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def session(request, server):
"""
try:
server.switch_client(session.get("session_id"))
pass
except exc.LibTmuxException:
# server.attach_session(session.get('session_id'))
pass
Expand Down
8 changes: 4 additions & 4 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

def test_allows_master_version(monkeypatch):
def mock_tmux_cmd(param):
class Hi(object):
class Hi:
stdout = ["tmux master"]
stderr = None

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

def test_allows_next_version(monkeypatch):
def mock_tmux_cmd(param):
class Hi(object):
class Hi:
stdout = ["tmux next-2.9"]
stderr = None

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

def test_get_version_openbsd(monkeypatch):
def mock_tmux_cmd(param):
class Hi(object):
class Hi:
stderr = ["tmux: unknown option -- V"]

return Hi()
Expand All @@ -80,7 +80,7 @@ class Hi(object):

def test_get_version_too_low(monkeypatch):
def mock_tmux_cmd(param):
class Hi(object):
class Hi:
stderr = ["tmux: unknown option -- V"]

return Hi()
Expand Down