From 700dc2e9876d0f2101fd341b4f8f4f36880b7268 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Wed, 18 Dec 2024 17:40:28 -0600 Subject: [PATCH] chore(ruff) Automated fixes for Python 3.9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ruff check . --select ALL --fix --unsafe-fixes --preview --show-fixes --ignore T201 --ignore PT014 --ignore RUF100; ruff format .; Fixed 186 errors: - conftest.py: 1 × UP006 (non-pep585-annotation) - docs/conf.py: 6 × UP006 (non-pep585-annotation) - src/libtmux/_internal/query_list.py: 31 × UP006 (non-pep585-annotation) 1 × RUF052 (used-dummy-variable) - src/libtmux/_vendor/version.py: 16 × UP006 (non-pep585-annotation) 8 × RUF052 (used-dummy-variable) 1 × F401 (unused-import) - src/libtmux/common.py: 9 × UP006 (non-pep585-annotation) 1 × F401 (unused-import) - src/libtmux/constants.py: 4 × UP006 (non-pep585-annotation) 1 × F401 (unused-import) - src/libtmux/neo.py: 3 × UP006 (non-pep585-annotation) - src/libtmux/pane.py: 8 × UP006 (non-pep585-annotation) - src/libtmux/pytest_plugin.py: 2 × UP006 (non-pep585-annotation) - src/libtmux/server.py: 19 × UP006 (non-pep585-annotation) - src/libtmux/session.py: 19 × UP006 (non-pep585-annotation) 5 × RUF052 (used-dummy-variable) - src/libtmux/test.py: 3 × UP006 (non-pep585-annotation) - src/libtmux/window.py: 14 × UP006 (non-pep585-annotation) - tests/_internal/test_query_list.py: 5 × UP006 (non-pep585-annotation) - tests/legacy_api/test_server.py: 1 × RUF052 (used-dummy-variable) - tests/legacy_api/test_session.py: 2 × UP006 (non-pep585-annotation) 1 × F401 (unused-import) 1 × RUF052 (used-dummy-variable) - tests/legacy_api/test_version.py: 3 × UP006 (non-pep585-annotation) 1 × TC006 (runtime-cast-value) - tests/legacy_api/test_window.py: 2 × UP006 (non-pep585-annotation) 1 × F401 (unused-import) - tests/test_dataclasses.py: 3 × UP006 (non-pep585-annotation) 3 × RUF052 (used-dummy-variable) - tests/test_server.py: 1 × RUF052 (used-dummy-variable) - tests/test_session.py: 2 × UP006 (non-pep585-annotation) 1 × RUF052 (used-dummy-variable) - tests/test_version.py: 3 × UP006 (non-pep585-annotation) 1 × TC006 (runtime-cast-value) - tests/test_window.py: 2 × UP006 (non-pep585-annotation) 1 × F401 (unused-import) Found 1893 errors (186 fixed, 1707 remaining). 44 files left unchanged --- conftest.py | 2 +- docs/conf.py | 8 ++-- src/libtmux/_internal/query_list.py | 68 ++++++++++++++--------------- src/libtmux/_vendor/version.py | 64 +++++++++++++-------------- src/libtmux/common.py | 20 ++++----- src/libtmux/constants.py | 7 ++- src/libtmux/neo.py | 6 +-- src/libtmux/pane.py | 16 +++---- src/libtmux/pytest_plugin.py | 4 +- src/libtmux/server.py | 36 +++++++-------- src/libtmux/session.py | 56 ++++++++++++------------ src/libtmux/test.py | 6 +-- src/libtmux/window.py | 26 +++++------ tests/_internal/test_query_list.py | 6 +-- tests/legacy_api/test_server.py | 4 +- tests/legacy_api/test_session.py | 9 ++-- tests/legacy_api/test_version.py | 6 +-- tests/legacy_api/test_window.py | 5 +-- tests/test_dataclasses.py | 28 ++++++------ tests/test_server.py | 4 +- tests/test_session.py | 8 ++-- tests/test_version.py | 6 +-- tests/test_window.py | 5 +-- 23 files changed, 198 insertions(+), 202 deletions(-) diff --git a/conftest.py b/conftest.py index b60c14cdf..0a5fee8f9 100644 --- a/conftest.py +++ b/conftest.py @@ -27,7 +27,7 @@ @pytest.fixture(autouse=True) def add_doctest_fixtures( request: pytest.FixtureRequest, - doctest_namespace: t.Dict[str, t.Any], + doctest_namespace: dict[str, t.Any], ) -> None: """Configure doctest fixtures for pytest-doctest.""" if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"): diff --git a/docs/conf.py b/docs/conf.py index dd9edab6f..dcdffada2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ sys.path.insert(0, str(cwd / "_ext")) # package data -about: t.Dict[str, str] = {} +about: dict[str, str] = {} with (project_src / "libtmux" / "__about__.py").open() as fp: exec(fp.read(), about) @@ -71,8 +71,8 @@ html_css_files = ["css/custom.css"] html_extra_path = ["manifest.json"] html_theme = "furo" -html_theme_path: t.List[str] = [] -html_theme_options: t.Dict[str, t.Union[str, t.List[t.Dict[str, str]]]] = { +html_theme_path: list[str] = [] +html_theme_options: dict[str, t.Union[str, list[dict[str, str]]]] = { "light_logo": "img/libtmux.svg", "dark_logo": "img/libtmux.svg", "footer_icons": [ @@ -138,7 +138,7 @@ } -def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]: +def linkcode_resolve(domain: str, info: dict[str, str]) -> 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 b5fcee7d0..79ef702d7 100644 --- a/src/libtmux/_internal/query_list.py +++ b/src/libtmux/_internal/query_list.py @@ -20,8 +20,8 @@ class LookupProtocol(t.Protocol): def __call__( self, - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: """Return callback for :class:`QueryList` filtering operators.""" ... @@ -43,7 +43,7 @@ class ObjectDoesNotExist(Exception): def keygetter( obj: "Mapping[str, t.Any]", path: str, -) -> t.Union[None, t.Any, str, t.List[str], "Mapping[str, str]"]: +) -> t.Union[None, t.Any, str, list[str], "Mapping[str, str]"]: """Fetch values in objects and keys, supported nested data. **With dictionaries**: @@ -151,15 +151,15 @@ def parse_lookup( def lookup_exact( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: return rhs == data def lookup_iexact( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if not isinstance(rhs, str) or not isinstance(data, str): return False @@ -168,8 +168,8 @@ def lookup_iexact( def lookup_contains( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if not isinstance(rhs, str) or not isinstance(data, (str, Mapping, list)): return False @@ -178,8 +178,8 @@ def lookup_contains( def lookup_icontains( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if not isinstance(rhs, str) or not isinstance(data, (str, Mapping, list)): return False @@ -193,8 +193,8 @@ def lookup_icontains( def lookup_startswith( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if not isinstance(rhs, str) or not isinstance(data, str): return False @@ -203,8 +203,8 @@ def lookup_startswith( def lookup_istartswith( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if not isinstance(rhs, str) or not isinstance(data, str): return False @@ -213,8 +213,8 @@ def lookup_istartswith( def lookup_endswith( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if not isinstance(rhs, str) or not isinstance(data, str): return False @@ -223,8 +223,8 @@ def lookup_endswith( def lookup_iendswith( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if not isinstance(rhs, str) or not isinstance(data, str): return False @@ -232,8 +232,8 @@ def lookup_iendswith( def lookup_in( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if isinstance(rhs, list): return data in rhs @@ -254,8 +254,8 @@ def lookup_in( def lookup_nin( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if isinstance(rhs, list): return data not in rhs @@ -276,8 +276,8 @@ def lookup_nin( def lookup_regex( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if isinstance(data, (str, bytes, re.Pattern)) and isinstance(rhs, (str, bytes)): return bool(re.search(rhs, data)) @@ -285,8 +285,8 @@ def lookup_regex( def lookup_iregex( - data: t.Union[str, t.List[str], "Mapping[str, str]"], - rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"], + data: t.Union[str, list[str], "Mapping[str, str]"], + rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"], ) -> bool: if isinstance(data, (str, bytes, re.Pattern)) and isinstance(rhs, (str, bytes)): return bool(re.search(rhs, data, re.IGNORECASE)) @@ -320,7 +320,7 @@ def __init__(self, op: str, *args: object) -> None: return super().__init__(f"{op} not in LOOKUP_NAME_MAP") -class QueryList(t.List[T], t.Generic[T]): +class QueryList(list[T], t.Generic[T]): """Filter list of object/dictionaries. For small, local datasets. *Experimental, unstable*. @@ -475,7 +475,7 @@ class QueryList(t.List[T], t.Generic[T]): def __init__(self, items: t.Optional["Iterable[T]"] = None) -> None: super().__init__(items if items is not None else []) - def items(self) -> t.List[t.Tuple[str, T]]: + def items(self) -> list[tuple[str, T]]: if self.pk_key is None: raise PKRequiredException return [(getattr(item, self.pk_key), item) for item in self] @@ -531,19 +531,19 @@ def filter_lookup(obj: t.Any) -> bool: return True if callable(matcher): - _filter = matcher + filter_ = matcher elif matcher is not None: - def val_match(obj: t.Union[str, t.List[t.Any], T]) -> bool: + def val_match(obj: t.Union[str, list[t.Any], T]) -> bool: if isinstance(matcher, list): return obj in matcher return bool(obj == matcher) - _filter = val_match + filter_ = val_match else: - _filter = filter_lookup + filter_ = filter_lookup - return self.__class__(k for k in self if _filter(k)) + return self.__class__(k for k in self if filter_(k)) def get( self, diff --git a/src/libtmux/_vendor/version.py b/src/libtmux/_vendor/version.py index 95d16d9d5..72af139db 100644 --- a/src/libtmux/_vendor/version.py +++ b/src/libtmux/_vendor/version.py @@ -12,29 +12,29 @@ import collections import itertools import re -from typing import Callable, Optional, SupportsInt, Tuple, Union +from typing import Callable, Optional, SupportsInt, Union from ._structures import Infinity, InfinityType, NegativeInfinity, NegativeInfinityType __all__ = ["VERSION_PATTERN", "InvalidVersion", "Version", "parse"] InfiniteTypes = Union[InfinityType, NegativeInfinityType] -PrePostDevType = Union[InfiniteTypes, Tuple[str, int]] +PrePostDevType = Union[InfiniteTypes, tuple[str, int]] SubLocalType = Union[InfiniteTypes, int, str] LocalType = Union[ NegativeInfinityType, - Tuple[ + tuple[ Union[ SubLocalType, - Tuple[SubLocalType, str], - Tuple[NegativeInfinityType, SubLocalType], + tuple[SubLocalType, str], + tuple[NegativeInfinityType, SubLocalType], ], ..., ], ] -CmpKey = Tuple[ +CmpKey = tuple[ int, - Tuple[int, ...], + tuple[int, ...], PrePostDevType, PrePostDevType, PrePostDevType, @@ -293,11 +293,11 @@ def epoch(self) -> int: >>> Version("1!2.0.0").epoch 1 """ - _epoch: int = self._version.epoch - return _epoch + epoch: int = self._version.epoch + return epoch @property - def release(self) -> Tuple[int, ...]: + def release(self) -> tuple[int, ...]: """The components of the "release" segment of the version. >>> Version("1.2.3").release @@ -310,11 +310,11 @@ def release(self) -> Tuple[int, ...]: Includes trailing zeroes but not the epoch or any pre-release / development / post-release suffixes. """ - _release: Tuple[int, ...] = self._version.release - return _release + release: tuple[int, ...] = self._version.release + return release @property - def pre(self) -> Optional[Tuple[str, int]]: + def pre(self) -> Optional[tuple[str, int]]: """The pre-release segment of the version. >>> print(Version("1.2.3").pre) @@ -326,8 +326,8 @@ def pre(self) -> Optional[Tuple[str, int]]: >>> Version("1.2.3rc1").pre ('rc', 1) """ - _pre: Optional[Tuple[str, int]] = self._version.pre - return _pre + pre: Optional[tuple[str, int]] = self._version.pre + return pre @property def post(self) -> Optional[int]: @@ -476,7 +476,7 @@ def micro(self) -> int: def _parse_letter_version( letter: str, number: Union[str, bytes, SupportsInt], -) -> Optional[Tuple[str, int]]: +) -> Optional[tuple[str, int]]: if letter: # We consider there to be an implicit 0 in a pre-release if there is # not a numeral associated with it. @@ -524,18 +524,18 @@ def _parse_local_version(local: str) -> Optional[LocalType]: def _cmpkey( epoch: int, - release: Tuple[int, ...], - pre: Optional[Tuple[str, int]], - post: Optional[Tuple[str, int]], - dev: Optional[Tuple[str, int]], - local: Optional[Tuple[SubLocalType]], + release: tuple[int, ...], + pre: Optional[tuple[str, int]], + post: Optional[tuple[str, int]], + dev: Optional[tuple[str, int]], + local: Optional[tuple[SubLocalType]], ) -> CmpKey: # When we compare a release version, we want to compare it with all of the # trailing zeros removed. So we'll use a reverse the list, drop all the now # leading zeros until we come to something non zero, then take the rest # re-reverse it back into the correct order and make it a tuple and use # that for our sorting key. - _release = tuple( + release_ = tuple( reversed(list(itertools.dropwhile(lambda x: x == 0, reversed(release)))), ) @@ -544,31 +544,31 @@ def _cmpkey( # if there is not a pre or a post segment. If we have one of those then # the normal sorting rules will handle this case correctly. if pre is None and post is None and dev is not None: - _pre: PrePostDevType = NegativeInfinity + pre_: PrePostDevType = NegativeInfinity # Versions without a pre-release (except as noted above) should sort after # those with one. elif pre is None: - _pre = Infinity + pre_ = Infinity else: - _pre = pre + pre_ = pre # Versions without a post segment should sort before those with one. if post is None: - _post: PrePostDevType = NegativeInfinity + post_: PrePostDevType = NegativeInfinity else: - _post = post + post_ = post # Versions without a development segment should sort after those with one. if dev is None: - _dev: PrePostDevType = Infinity + dev_: PrePostDevType = Infinity else: - _dev = dev + dev_ = dev if local is None: # Versions without a local segment should sort before those with one. - _local: LocalType = NegativeInfinity + local_: LocalType = NegativeInfinity else: # Versions with a local segment need that segment parsed to implement # the sorting rules in PEP440. @@ -577,8 +577,8 @@ def _cmpkey( # - Numeric segments sort numerically # - Shorter versions sort before longer versions when the prefixes # match exactly - _local = tuple( + local_ = tuple( (i, "") if isinstance(i, int) else (NegativeInfinity, i) for i in local ) - return epoch, _release, _pre, _post, _dev, _local + return epoch, release_, pre_, post_, dev_, local_ diff --git a/src/libtmux/common.py b/src/libtmux/common.py index 854c340fe..62e82d12b 100644 --- a/src/libtmux/common.py +++ b/src/libtmux/common.py @@ -11,7 +11,7 @@ import subprocess import sys import typing as t -from typing import Dict, Optional, Union +from typing import Optional, Union from . import exc from ._compat import LooseVersion, console_to_str, str_from_console @@ -25,10 +25,10 @@ #: Most recent version of tmux supported TMUX_MAX_VERSION = "3.4" -SessionDict = t.Dict[str, t.Any] -WindowDict = t.Dict[str, t.Any] -WindowOptionDict = t.Dict[str, t.Any] -PaneDict = t.Dict[str, t.Any] +SessionDict = dict[str, t.Any] +WindowDict = dict[str, t.Any] +WindowOptionDict = dict[str, t.Any] +PaneDict = dict[str, t.Any] class EnvironmentMixin: @@ -116,7 +116,7 @@ def remove_environment(self, name: str) -> None: msg = f"tmux set-environment stderr: {cmd.stderr}" raise ValueError(msg) - def show_environment(self) -> Dict[str, Union[bool, str]]: + def show_environment(self) -> dict[str, Union[bool, str]]: """Show environment ``$ tmux show-environment -t [session]``. Return dict of environment variables for the session. @@ -137,7 +137,7 @@ def show_environment(self) -> Dict[str, Union[bool, str]]: cmd = self.cmd(*tmux_args) output = cmd.stdout opts = [tuple(item.split("=", 1)) for item in output] - opts_dict: t.Dict[str, t.Union[str, bool]] = {} + opts_dict: dict[str, t.Union[str, bool]] = {} for _t in opts: if len(_t) == 2: opts_dict[_t[0]] = _t[1] @@ -165,7 +165,7 @@ def getenv(self, name: str) -> Optional[t.Union[str, bool]]: str Value of environment variable """ - tmux_args: t.Tuple[t.Union[str, int], ...] = () + tmux_args: tuple[t.Union[str, int], ...] = () tmux_args += ("show-environment",) if self._add_option: @@ -174,7 +174,7 @@ def getenv(self, name: str) -> Optional[t.Union[str, bool]]: cmd = self.cmd(*tmux_args) output = cmd.stdout opts = [tuple(item.split("=", 1)) for item in output] - opts_dict: t.Dict[str, t.Union[str, bool]] = {} + opts_dict: dict[str, t.Union[str, bool]] = {} for _t in opts: if len(_t) == 2: opts_dict[_t[0]] = _t[1] @@ -446,7 +446,7 @@ def session_check_name(session_name: t.Optional[str]) -> None: raise exc.BadSessionName(reason="contains colons", session_name=session_name) -def handle_option_error(error: str) -> t.Type[exc.OptionError]: +def handle_option_error(error: str) -> type[exc.OptionError]: """Raise exception if error in option command found. In tmux 3.0, show-option and show-window-option return invalid option instead of diff --git a/src/libtmux/constants.py b/src/libtmux/constants.py index ea8bcab3b..41698a8f0 100644 --- a/src/libtmux/constants.py +++ b/src/libtmux/constants.py @@ -1,7 +1,6 @@ """Constant variables for libtmux.""" import enum -import typing as t class ResizeAdjustmentDirection(enum.Enum): @@ -13,7 +12,7 @@ class ResizeAdjustmentDirection(enum.Enum): Right = "RIGHT" -RESIZE_ADJUSTMENT_DIRECTION_FLAG_MAP: t.Dict[ResizeAdjustmentDirection, str] = { +RESIZE_ADJUSTMENT_DIRECTION_FLAG_MAP: dict[ResizeAdjustmentDirection, str] = { ResizeAdjustmentDirection.Up: "-U", ResizeAdjustmentDirection.Down: "-D", ResizeAdjustmentDirection.Left: "-L", @@ -28,7 +27,7 @@ class WindowDirection(enum.Enum): After = "AFTER" -WINDOW_DIRECTION_FLAG_MAP: t.Dict[WindowDirection, str] = { +WINDOW_DIRECTION_FLAG_MAP: dict[WindowDirection, str] = { WindowDirection.Before: "-b", WindowDirection.After: "-a", } @@ -43,7 +42,7 @@ class PaneDirection(enum.Enum): Left = "LEFT" -PANE_DIRECTION_FLAG_MAP: t.Dict[PaneDirection, t.List[str]] = { +PANE_DIRECTION_FLAG_MAP: dict[PaneDirection, list[str]] = { # -v is assumed, but for explicitness it is passed PaneDirection.Above: ["-v", "-b"], PaneDirection.Below: ["-v"], diff --git a/src/libtmux/neo.py b/src/libtmux/neo.py index e3f78adb0..f644014e1 100644 --- a/src/libtmux/neo.py +++ b/src/libtmux/neo.py @@ -17,8 +17,8 @@ logger = logging.getLogger(__name__) -OutputRaw = t.Dict[str, t.Any] -OutputsRaw = t.List[OutputRaw] +OutputRaw = dict[str, t.Any] +OutputsRaw = list[OutputRaw] """ @@ -195,7 +195,7 @@ def fetch_objs( """Fetch a listing of raw data from a tmux command.""" formats = list(Obj.__dataclass_fields__.keys()) - cmd_args: t.List[t.Union[str, int]] = [] + cmd_args: list[t.Union[str, int]] = [] if server.socket_name: cmd_args.insert(0, f"-L{server.socket_name}") diff --git a/src/libtmux/pane.py b/src/libtmux/pane.py index 7f0ff0c28..9586e68e5 100644 --- a/src/libtmux/pane.py +++ b/src/libtmux/pane.py @@ -213,7 +213,7 @@ def resize( 2. Manual resizing: ``height`` and / or ``width``. 3. Zoom / Unzoom: ``zoom``. """ - tmux_args: t.Tuple[str, ...] = () + tmux_args: tuple[str, ...] = () # Adjustments if adjustment_direction: @@ -262,7 +262,7 @@ def capture_pane( self, start: t.Union["t.Literal['-']", t.Optional[int]] = None, end: t.Union["t.Literal['-']", t.Optional[int]] = None, - ) -> t.Union[str, t.List[str]]: + ) -> t.Union[str, list[str]]: """Capture text from pane. ``$ tmux capture-pane`` to pane. @@ -352,7 +352,7 @@ def display_message( self, cmd: str, get_text: "t.Literal[True]", - ) -> t.Union[str, t.List[str]]: ... + ) -> t.Union[str, list[str]]: ... @overload def display_message(self, cmd: str, get_text: "t.Literal[False]") -> None: ... @@ -361,7 +361,7 @@ def display_message( self, cmd: str, get_text: bool = False, - ) -> t.Optional[t.Union[str, t.List[str]]]: + ) -> t.Optional[t.Union[str, list[str]]]: """Display message to pane. Displays a message in target-client status line. @@ -423,7 +423,7 @@ def kill( >>> one_pane_to_rule_them_all in window.panes True """ - flags: t.Tuple[str, ...] = () + flags: tuple[str, ...] = () if all_except: flags += ("-a",) @@ -507,7 +507,7 @@ def split( zoom: t.Optional[bool] = None, shell: t.Optional[str] = None, size: t.Optional[t.Union[str, int]] = None, - environment: t.Optional[t.Dict[str, str]] = None, + environment: t.Optional[dict[str, str]] = None, ) -> "Pane": """Split window and return :class:`Pane`, by default beneath current pane. @@ -593,7 +593,7 @@ def split( """ tmux_formats = ["#{pane_id}" + FORMAT_SEPARATOR] - tmux_args: t.Tuple[str, ...] = () + tmux_args: tuple[str, ...] = () if direction: tmux_args += tuple(PANE_DIRECTION_FLAG_MAP[direction]) @@ -827,7 +827,7 @@ def split_window( shell: t.Optional[str] = None, size: t.Optional[t.Union[str, int]] = None, percent: t.Optional[int] = None, # deprecated - environment: t.Optional[t.Dict[str, str]] = None, + environment: t.Optional[dict[str, str]] = None, ) -> "Pane": # New Pane, not self """Split window at pane and return newly created :class:`Pane`. diff --git a/src/libtmux/pytest_plugin.py b/src/libtmux/pytest_plugin.py index 4d9521fc4..3dcca9963 100644 --- a/src/libtmux/pytest_plugin.py +++ b/src/libtmux/pytest_plugin.py @@ -147,7 +147,7 @@ def fin() -> None: @pytest.fixture -def session_params() -> t.Dict[str, t.Any]: +def session_params() -> dict[str, t.Any]: """Return new, temporary :class:`libtmux.Session`. >>> import pytest @@ -187,7 +187,7 @@ def session_params() -> t.Dict[str, t.Any]: @pytest.fixture def session( request: pytest.FixtureRequest, - session_params: t.Dict[str, t.Any], + session_params: dict[str, t.Any], server: Server, ) -> "Session": """Return new, temporary :class:`libtmux.Session`. diff --git a/src/libtmux/server.py b/src/libtmux/server.py index 429b39836..04e07b75c 100644 --- a/src/libtmux/server.py +++ b/src/libtmux/server.py @@ -111,8 +111,8 @@ def __init__( **kwargs: t.Any, ) -> None: EnvironmentMixin.__init__(self, "-g") - self._windows: t.List[WindowDict] = [] - self._panes: t.List[PaneDict] = [] + self._windows: list[WindowDict] = [] + self._panes: list[PaneDict] = [] if socket_path is not None: self.socket_path = socket_path @@ -161,7 +161,7 @@ def raise_if_dead(self) -> None: if tmux_bin is None: raise exc.TmuxCommandNotFound - cmd_args: t.List[str] = ["list-sessions"] + cmd_args: list[str] = ["list-sessions"] if self.socket_name: cmd_args.insert(0, f"-L{self.socket_name}") if self.socket_path: @@ -227,8 +227,8 @@ def cmd( Renamed from ``.tmux`` to ``.cmd``. """ - svr_args: t.List[t.Union[str, int]] = [cmd] - cmd_args: t.List[t.Union[str, int]] = [] + svr_args: list[t.Union[str, int]] = [cmd] + cmd_args: list[t.Union[str, int]] = [] if self.socket_name: svr_args.insert(0, f"-L{self.socket_name}") if self.socket_path: @@ -248,7 +248,7 @@ def cmd( return tmux_cmd(*svr_args, *cmd_args) @property - def attached_sessions(self) -> t.List[Session]: + def attached_sessions(self) -> list[Session]: """Return active :class:`Session`s. Examples @@ -382,7 +382,7 @@ def new_session( window_command: t.Optional[str] = None, x: t.Optional[t.Union[int, "DashLiteral"]] = None, y: t.Optional[t.Union[int, "DashLiteral"]] = None, - environment: t.Optional[t.Dict[str, str]] = None, + environment: t.Optional[dict[str, str]] = None, *args: t.Any, **kwargs: t.Any, ) -> Session: @@ -476,7 +476,7 @@ def new_session( if env: del os.environ["TMUX"] - tmux_args: t.Tuple[t.Union[str, int], ...] = ( + tmux_args: tuple[t.Union[str, int], ...] = ( "-P", "-F#{session_id}", # output ) @@ -541,7 +541,7 @@ def sessions(self) -> QueryList[Session]: :meth:`.sessions.get() ` and :meth:`.sessions.filter() ` """ - sessions: t.List[Session] = [] + sessions: list[Session] = [] try: for obj in fetch_objs( @@ -562,7 +562,7 @@ def windows(self) -> QueryList[Window]: :meth:`.windows.get() ` and :meth:`.windows.filter() ` """ - windows: t.List[Window] = [ + windows: list[Window] = [ Window(server=self, **obj) for obj in fetch_objs( list_cmd="list-windows", @@ -581,7 +581,7 @@ def panes(self) -> QueryList[Pane]: :meth:`.panes.get() ` and :meth:`.panes.filter() ` """ - panes: t.List[Pane] = [ + panes: list[Pane] = [ Pane(server=self, **obj) for obj in fetch_objs( list_cmd="list-panes", @@ -635,7 +635,7 @@ def kill_server(self) -> None: ) self.cmd("kill-server") - def _list_panes(self) -> t.List[PaneDict]: + def _list_panes(self) -> list[PaneDict]: """Return list of panes in :py:obj:`dict` form. Retrieved from ``$ tmux(1) list-panes`` stdout. @@ -689,7 +689,7 @@ def get_by_id(self, session_id: str) -> t.Optional[Session]: ) return self.sessions.get(session_id=session_id, default=None) - def where(self, kwargs: t.Dict[str, t.Any]) -> t.List[Session]: + def where(self, kwargs: dict[str, t.Any]) -> list[Session]: """Filter through sessions, return list of :class:`Session`. .. deprecated:: 0.16 @@ -707,7 +707,7 @@ def where(self, kwargs: t.Dict[str, t.Any]) -> t.List[Session]: except IndexError: return [] - def find_where(self, kwargs: t.Dict[str, t.Any]) -> t.Optional[Session]: + def find_where(self, kwargs: dict[str, t.Any]) -> t.Optional[Session]: """Filter through sessions, return first :class:`Session`. .. deprecated:: 0.16 @@ -722,7 +722,7 @@ def find_where(self, kwargs: t.Dict[str, t.Any]) -> t.Optional[Session]: ) return self.sessions.get(default=None, **kwargs) - def _list_windows(self) -> t.List[WindowDict]: + def _list_windows(self) -> list[WindowDict]: """Return list of windows in :py:obj:`dict` form. Retrieved from ``$ tmux(1) list-windows`` stdout. @@ -759,7 +759,7 @@ def _update_windows(self) -> "Server": return self @property - def _sessions(self) -> t.List[SessionDict]: + def _sessions(self) -> list[SessionDict]: """Property / alias to return :meth:`~._list_sessions`. .. deprecated:: 0.16 @@ -774,7 +774,7 @@ def _sessions(self) -> t.List[SessionDict]: ) return self._list_sessions() - def _list_sessions(self) -> t.List["SessionDict"]: + def _list_sessions(self) -> list["SessionDict"]: """Return list of session object dictionaries. .. deprecated:: 0.16 @@ -788,7 +788,7 @@ def _list_sessions(self) -> t.List["SessionDict"]: ) return [s.__dict__ for s in self.sessions] - def list_sessions(self) -> t.List[Session]: + def list_sessions(self) -> list[Session]: """Return list of :class:`Session` from the ``tmux(1)`` session. .. deprecated:: 0.16 diff --git a/src/libtmux/session.py b/src/libtmux/session.py index 4eec19d86..785459fd1 100644 --- a/src/libtmux/session.py +++ b/src/libtmux/session.py @@ -106,7 +106,7 @@ def windows(self) -> QueryList["Window"]: :meth:`.windows.get() ` and :meth:`.windows.filter() ` """ - windows: t.List[Window] = [ + windows: list[Window] = [ Window(server=self.server, **obj) for obj in fetch_objs( list_cmd="list-windows", @@ -126,7 +126,7 @@ def panes(self) -> QueryList["Pane"]: :meth:`.panes.get() ` and :meth:`.panes.filter() ` """ - panes: t.List[Pane] = [ + panes: list[Pane] = [ Pane(server=self.server, **obj) for obj in fetch_objs( list_cmd="list-panes", @@ -194,7 +194,7 @@ def set_option( self, option: str, value: t.Union[str, int], - _global: bool = False, + global_: bool = False, ) -> "Session": """Set option ``$ tmux set-option