Skip to content

Commit

Permalink
chore(ruff) Automated fixes for Python 3.9
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tony committed Dec 18, 2024
1 parent 6e09866 commit 700dc2e
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 202 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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.
Expand Down
68 changes: 34 additions & 34 deletions src/libtmux/_internal/query_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
...
Expand All @@ -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**:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -223,17 +223,17 @@ 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
return data.lower().endswith(rhs.lower())


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
Expand All @@ -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
Expand All @@ -276,17 +276,17 @@ 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))
return False


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))
Expand Down Expand Up @@ -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*.
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
64 changes: 32 additions & 32 deletions src/libtmux/_vendor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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]:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)))),
)

Expand All @@ -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.
Expand All @@ -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_
Loading

0 comments on commit 700dc2e

Please sign in to comment.