diff --git a/conftest.py b/conftest.py index d45b5ee5b..299041497 100644 --- a/conftest.py +++ b/conftest.py @@ -12,7 +12,6 @@ import typing as t import pytest - from _pytest.doctest import DoctestItem from libtmux.pytest_plugin import USING_ZSH diff --git a/docs/conf.py b/docs/conf.py index 522cdcbc5..7ce307b99 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,8 +6,8 @@ import pathlib import typing as t -import libtmux # NOQA -from libtmux import test # NOQA +import libtmux +from libtmux import test if t.TYPE_CHECKING: from sphinx.application import Sphinx @@ -168,7 +168,7 @@ def linkcode_resolve( domain: str, info: t.Dict[str, str] -) -> t.Union[None, str]: # NOQA: C901 +) -> t.Union[None, str]: """ Determine the URL corresponding to Python object diff --git a/src/libtmux/_internal/query_list.py b/src/libtmux/_internal/query_list.py index 7fa3d4170..487ca8deb 100644 --- a/src/libtmux/_internal/query_list.py +++ b/src/libtmux/_internal/query_list.py @@ -123,7 +123,7 @@ def lookup_icontains( if isinstance(data, str): return rhs.lower() in data.lower() if isinstance(data, Mapping): - return rhs.lower() in [k.lower() for k in data.keys()] + return rhs.lower() in [k.lower() for k in data] return False @@ -183,7 +183,6 @@ def lookup_in( return rhs in data # TODO: Add a deep Mappingionary matcher # if isinstance(rhs, Mapping) and isinstance(data, Mapping): - # return rhs.items() not in data.items() except Exception: return False return False @@ -205,7 +204,6 @@ def lookup_nin( return rhs not in data # TODO: Add a deep Mappingionary matcher # if isinstance(rhs, Mapping) and isinstance(data, Mapping): - # return rhs.items() not in data.items() except Exception: return False return False @@ -293,10 +291,6 @@ def __eq__( self, other: object, # other: Union[ - # "QueryList[T]", - # List[Mapping[str, str]], - # List[Mapping[str, int]], - # List[Mapping[str, Union[str, Mapping[str, Union[List[str], str]]]]], # ], ) -> bool: data = other diff --git a/src/libtmux/formats.py b/src/libtmux/formats.py index 6f36799f1..eff1d7fed 100644 --- a/src/libtmux/formats.py +++ b/src/libtmux/formats.py @@ -41,14 +41,12 @@ ] WINDOW_FORMATS = [ - # format_window() "window_id", "window_name", "window_width", "window_height", "window_layout", "window_panes", - # format_winlink() "window_index", "window_flags", "window_active", diff --git a/src/libtmux/neo.py b/src/libtmux/neo.py index 70267b07d..ed2f8de76 100644 --- a/src/libtmux/neo.py +++ b/src/libtmux/neo.py @@ -40,16 +40,13 @@ class Obj: alternate_saved_x: t.Union[str, None] = None alternate_saved_y: t.Union[str, None] = None # See QUIRK_TMUX_3_1_X_0001 - # buffer_created: t.Union[str, None] = None buffer_name: t.Union[str, None] = None buffer_sample: t.Union[str, None] = None buffer_size: t.Union[str, None] = None # See QUIRK_TMUX_3_1_X_0001 - # client_activity: t.Union[str, None] = None client_cell_height: t.Union[str, None] = None client_cell_width: t.Union[str, None] = None # See QUIRK_TMUX_3_1_X_0001 - # client_created: t.Union[str, None] = None client_discarded: t.Union[str, None] = None client_flags: t.Union[str, None] = None client_height: t.Union[str, None] = None @@ -182,11 +179,11 @@ def _refresh( def fetch_objs( - server: "Server", list_cmd: "ListCmd", list_extra_args: "ListExtraArgs" = None + server: "Server", list_cmd: "ListCmd", list_extra_args: "t.Optional[ListExtraArgs]" = None ) -> OutputsRaw: formats = list(Obj.__dataclass_fields__.keys()) - cmd_args: t.List[t.Union[str, int]] = list() + cmd_args: t.List[t.Union[str, int]] = [] if server.socket_name: cmd_args.insert(0, f"-L{server.socket_name}") @@ -229,7 +226,7 @@ def fetch_obj( obj_key: str, obj_id: str, list_cmd: "ListCmd" = "list-panes", - list_extra_args: "ListExtraArgs" = None, + list_extra_args: "t.Optional[ListExtraArgs]" = None, ) -> OutputRaw: obj_formatters_filtered = fetch_objs( server=server, list_cmd=list_cmd, list_extra_args=list_extra_args diff --git a/src/libtmux/pytest_plugin.py b/src/libtmux/pytest_plugin.py index f24bfdbd0..b90741044 100644 --- a/src/libtmux/pytest_plugin.py +++ b/src/libtmux/pytest_plugin.py @@ -1,3 +1,4 @@ +import contextlib import getpass import logging import os @@ -80,7 +81,7 @@ def clear_env(monkeypatch: pytest.MonkeyPatch) -> None: tmux show-environment tests were being interrupted due to a lot of crazy env vars. """ - for k, v in os.environ.items(): + for k, _v in os.environ.items(): if not any( needle in k.lower() for needle in [ @@ -236,16 +237,14 @@ def session( session_id = session.session_id assert session_id is not None - try: + with contextlib.suppress(exc.LibTmuxException): server.switch_client(target_session=session_id) - except exc.LibTmuxException: - # server.attach_session(session.get('session_id')) - pass + for old_test_session in old_test_sessions: logger.debug(f"Old test test session {old_test_session} found. Killing it.") server.kill_session(old_test_session) - assert TEST_SESSION_NAME == session.session_name + assert session.session_name == TEST_SESSION_NAME assert TEST_SESSION_NAME != "tmuxp" return session diff --git a/src/libtmux/server.py b/src/libtmux/server.py index a281d202b..37da33081 100644 --- a/src/libtmux/server.py +++ b/src/libtmux/server.py @@ -169,7 +169,7 @@ def raise_if_dead(self) -> None: if self.config_file: cmd_args.insert(0, f"-f{self.config_file}") - subprocess.check_call([tmux_bin] + cmd_args) + subprocess.check_call([tmux_bin, *cmd_args]) # # Command @@ -227,7 +227,7 @@ def attached_sessions(self) -> t.List[Session]: """ try: sessions = self.sessions - attached_sessions = list() + attached_sessions = [] for session in sessions: attached = session.session_attached @@ -239,7 +239,6 @@ def attached_sessions(self) -> t.List[Session]: continue return attached_sessions - # return [Session(**s) for s in attached_sessions] or None except Exception: return [] @@ -339,7 +338,7 @@ def attach_session(self, target_session: t.Optional[str] = None) -> None: """ session_check_name(target_session) - tmux_args: t.Tuple[str, ...] = tuple() + tmux_args: t.Tuple[str, ...] = () if target_session: tmux_args += ("-t%s" % target_session,) @@ -574,7 +573,7 @@ def __repr__(self) -> str: elif self.socket_path is not None: return ( f"{self.__class__.__name__}" - f"(socket_path={getattr(self, 'socket_path')})" + f"(socket_path={self.socket_path})" ) return f"{self.__class__.__name__}" f"(socket_path=/tmp/tmux-1000/default)" diff --git a/src/libtmux/session.py b/src/libtmux/session.py index 1793a687f..e993616e4 100644 --- a/src/libtmux/session.py +++ b/src/libtmux/session.py @@ -151,7 +151,7 @@ def cmd(self, *args: t.Any, **kwargs: t.Any) -> tmux_cmd: # if -t is not set in any arg yet if not any("-t" in str(x) for x in args): # insert -t immediately after 1st arg, as per tmux format - new_args: t.Tuple[str, ...] = tuple() + new_args: t.Tuple[str, ...] = () new_args += (args[0],) assert isinstance(self.session_id, str) new_args += ( @@ -163,7 +163,6 @@ def cmd(self, *args: t.Any, **kwargs: t.Any) -> tmux_cmd: return self.server.cmd(*args, **kwargs) # - # Commands (tmux-like) # def set_option( self, option: str, value: t.Union[str, int], _global: bool = False @@ -197,7 +196,7 @@ def set_option( elif isinstance(value, bool) and not value: value = "off" - tmux_args: t.Tuple[t.Union[str, int], ...] = tuple() + tmux_args: t.Tuple[t.Union[str, int], ...] = () if _global: tmux_args += ("-g",) @@ -240,7 +239,7 @@ def show_options( Uses ``_global`` for keyword name instead of ``global`` to avoid colliding with reserved keyword. """ - tmux_args: t.Tuple[str, ...] = tuple() + tmux_args: t.Tuple[str, ...] = () if _global: tmux_args += ("-g",) @@ -288,7 +287,7 @@ def show_option( Test and return True/False for on/off string. """ - tmux_args: t.Tuple[str, ...] = tuple() + tmux_args: t.Tuple[str, ...] = () if _global: tmux_args += ("-g",) @@ -476,7 +475,7 @@ def new_window( ------- :class:`Window` """ - window_args: t.Tuple[str, ...] = tuple() + window_args: t.Tuple[str, ...] = () if not attach: window_args += ("-d",) @@ -494,8 +493,7 @@ def new_window( window_args += ( # empty string for window_index will use the first one available - "-t%s:%s" - % (self.session_id, window_index), + f"-t{self.session_id}:{window_index}", ) if environment: diff --git a/src/libtmux/test.py b/src/libtmux/test.py index 861ac6dda..c1c996218 100644 --- a/src/libtmux/test.py +++ b/src/libtmux/test.py @@ -305,7 +305,7 @@ class EnvironmentVarGuard: def __init__(self) -> None: self._environ = os.environ self._unset: t.Set[str] = set() - self._reset: t.Dict[str, str] = dict() + self._reset: t.Dict[str, str] = {} def set(self, envvar: str, value: str) -> None: if envvar not in self._environ: diff --git a/src/libtmux/window.py b/src/libtmux/window.py index 072707a3d..e251f1e97 100644 --- a/src/libtmux/window.py +++ b/src/libtmux/window.py @@ -125,7 +125,6 @@ def panes(self) -> QueryList["Pane"]: # type: ignore return QueryList(panes) # - # Command (pane-scoped) # def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> tmux_cmd: """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: ``args`` will override using the object's ``window_id`` as target. """ if not any(arg.startswith("-t") for arg in args): - args = ("-t", self.window_id) + args + args = ("-t", self.window_id, *args) return self.server.cmd(cmd, *args, **kwargs) # - # Commands (tmux-like) # def select_pane(self, target_pane: t.Union[str, int]) -> t.Optional["Pane"]: """ @@ -219,21 +217,18 @@ def split_window( """ tmux_formats = ["#{pane_id}" + FORMAT_SEPARATOR] - # '-t%s' % self.attached_pane.get('pane_id'), # 2013-10-18 LOOK AT THIS, rm'd it.. - tmux_args: t.Tuple[str, ...] = tuple() + tmux_args: t.Tuple[str, ...] = () if target is not None: tmux_args += ("-t%s" % target,) else: if len(self.panes): tmux_args += ( - "-t%s:%s.%s" - % (self.session_id, self.window_id, self.panes[0].pane_index), + f"-t{self.session_id}:{self.window_id}.{self.panes[0].pane_index}", ) else: - tmux_args += ("-t%s:%s" % (self.session_id, self.window_id),) - # tmux_args += ("-t%s" % self.panes[0].pane_id,) + tmux_args += (f"-t{self.session_id}:{self.window_id}",) if vertical: tmux_args += ("-v",) @@ -313,7 +308,7 @@ def select_layout(self, layout: t.Optional[str] = None) -> "Window": 'custom' custom dimensions (see :term:`tmux(1)` manpages). """ - cmd = ["select-layout", "-t{}:{}".format(self.session_id, self.window_index)] + cmd = ["select-layout", f"-t{self.session_id}:{self.window_index}"] if layout: # tmux allows select-layout without args cmd.append(layout) @@ -349,7 +344,7 @@ def set_window_option(self, option: str, value: t.Union[int, str]) -> "Window": cmd = self.cmd( "set-window-option", - "-t{}:{}".format(self.session_id, self.window_index), + f"-t{self.session_id}:{self.window_index}", option, value, ) @@ -375,7 +370,7 @@ def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict" g : str, optional Pass ``-g`` flag for global variable, default False. """ - tmux_args: t.Tuple[str, ...] = tuple() + tmux_args: t.Tuple[str, ...] = () if g: tmux_args += ("-g",) @@ -419,7 +414,7 @@ def show_window_option( :exc:`exc.OptionError`, :exc:`exc.UnknownOption`, :exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption` """ - tmux_args: t.Tuple[t.Union[str, int], ...] = tuple() + tmux_args: t.Tuple[t.Union[str, int], ...] = () if g: tmux_args += ("-g",) @@ -486,7 +481,7 @@ def kill_window(self) -> None: proc = self.cmd( "kill-window", - "-t{}:{}".format(self.session_id, self.window_index), + f"-t{self.session_id}:{self.window_index}", ) if proc.stderr: @@ -510,7 +505,7 @@ def move_window( session = session or self.session_id proc = self.cmd( "move-window", - "-s{}:{}".format(self.session_id, self.window_index), + f"-s{self.session_id}:{self.window_index}", f"-t{session}:{destination}", ) diff --git a/tests/legacy_api/test_common.py b/tests/legacy_api/test_common.py index da9bcdeea..3441ff0cc 100644 --- a/tests/legacy_api/test_common.py +++ b/tests/legacy_api/test_common.py @@ -62,7 +62,7 @@ def mock_tmux_cmd(*args: t.Any, **kwargs: t.Any) -> Hi: assert has_minimum_version() assert has_gte_version(TMUX_MIN_VERSION) assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version" - assert TMUX_NEXT_VERSION == get_version() + assert get_version() == TMUX_NEXT_VERSION def test_get_version_openbsd(monkeypatch: pytest.MonkeyPatch) -> None: diff --git a/tests/legacy_api/test_server.py b/tests/legacy_api/test_server.py index d7830fd0b..9cc03f463 100644 --- a/tests/legacy_api/test_server.py +++ b/tests/legacy_api/test_server.py @@ -71,12 +71,12 @@ def test_show_environment(server: Server) -> None: def test_getenv(server: Server, session: Session) -> None: """Set environment then Server.show_environment(key).""" server.set_environment("FOO", "BAR") - assert "BAR" == server.getenv("FOO") + assert server.getenv("FOO") == "BAR" server.set_environment("FOO", "DAR") - assert "DAR" == server.getenv("FOO") + assert server.getenv("FOO") == "DAR" - assert "DAR" == server.show_environment()["FOO"] + assert server.show_environment()["FOO"] == "DAR" def test_show_environment_not_set(server: Server) -> None: diff --git a/tests/test_common.py b/tests/test_common.py index ca0705508..f158af127 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -61,7 +61,7 @@ def mock_tmux_cmd(*args: t.Any, **kwargs: t.Any) -> Hi: assert has_minimum_version() assert has_gte_version(TMUX_MIN_VERSION) assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version" - assert TMUX_NEXT_VERSION == get_version() + assert get_version() == TMUX_NEXT_VERSION def test_get_version_openbsd(monkeypatch: pytest.MonkeyPatch) -> None: diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py index 531932aa8..3ebb23b74 100644 --- a/tests/test_pytest_plugin.py +++ b/tests/test_pytest_plugin.py @@ -53,7 +53,6 @@ def test_repo_git_remote_checkout( first_test_key = list(files.keys())[0] first_test_filename = str(tests_path / first_test_key) - # Setup: Files tests_path.mkdir() for file_name, text in files.items(): test_file = tests_path / file_name diff --git a/tests/test_server.py b/tests/test_server.py index 711964e27..9731632fe 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -71,12 +71,12 @@ def test_show_environment(server: Server) -> None: def test_getenv(server: Server, session: Session) -> None: """Set environment then Server.show_environment(key).""" server.set_environment("FOO", "BAR") - assert "BAR" == server.getenv("FOO") + assert server.getenv("FOO") == "BAR" server.set_environment("FOO", "DAR") - assert "DAR" == server.getenv("FOO") + assert server.getenv("FOO") == "DAR" - assert "DAR" == server.show_environment()["FOO"] + assert server.show_environment()["FOO"] == "DAR" def test_show_environment_not_set(server: Server) -> None: