Skip to content

Commit 99cf9d0

Browse files
committed
chore(ruff) Automated fixes for Python 3.9
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
1 parent ebc4d69 commit 99cf9d0

23 files changed

+198
-202
lines changed

conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@pytest.fixture(autouse=True)
2828
def add_doctest_fixtures(
2929
request: pytest.FixtureRequest,
30-
doctest_namespace: t.Dict[str, t.Any],
30+
doctest_namespace: dict[str, t.Any],
3131
) -> None:
3232
"""Configure doctest fixtures for pytest-doctest."""
3333
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):

docs/conf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
sys.path.insert(0, str(cwd / "_ext"))
2323

2424
# package data
25-
about: t.Dict[str, str] = {}
25+
about: dict[str, str] = {}
2626
with (project_src / "libtmux" / "__about__.py").open() as fp:
2727
exec(fp.read(), about)
2828

@@ -71,8 +71,8 @@
7171
html_css_files = ["css/custom.css"]
7272
html_extra_path = ["manifest.json"]
7373
html_theme = "furo"
74-
html_theme_path: t.List[str] = []
75-
html_theme_options: t.Dict[str, t.Union[str, t.List[t.Dict[str, str]]]] = {
74+
html_theme_path: list[str] = []
75+
html_theme_options: dict[str, t.Union[str, list[dict[str, str]]]] = {
7676
"light_logo": "img/libtmux.svg",
7777
"dark_logo": "img/libtmux.svg",
7878
"footer_icons": [
@@ -138,7 +138,7 @@
138138
}
139139

140140

141-
def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
141+
def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
142142
"""
143143
Determine the URL corresponding to Python object.
144144

src/libtmux/_internal/query_list.py

+34-34
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class LookupProtocol(t.Protocol):
2020

2121
def __call__(
2222
self,
23-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
24-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
23+
data: t.Union[str, list[str], "Mapping[str, str]"],
24+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
2525
) -> bool:
2626
"""Return callback for :class:`QueryList` filtering operators."""
2727
...
@@ -43,7 +43,7 @@ class ObjectDoesNotExist(Exception):
4343
def keygetter(
4444
obj: "Mapping[str, t.Any]",
4545
path: str,
46-
) -> t.Union[None, t.Any, str, t.List[str], "Mapping[str, str]"]:
46+
) -> t.Union[None, t.Any, str, list[str], "Mapping[str, str]"]:
4747
"""Fetch values in objects and keys, supported nested data.
4848
4949
**With dictionaries**:
@@ -151,15 +151,15 @@ def parse_lookup(
151151

152152

153153
def lookup_exact(
154-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
155-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
154+
data: t.Union[str, list[str], "Mapping[str, str]"],
155+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
156156
) -> bool:
157157
return rhs == data
158158

159159

160160
def lookup_iexact(
161-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
162-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
161+
data: t.Union[str, list[str], "Mapping[str, str]"],
162+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
163163
) -> bool:
164164
if not isinstance(rhs, str) or not isinstance(data, str):
165165
return False
@@ -168,8 +168,8 @@ def lookup_iexact(
168168

169169

170170
def lookup_contains(
171-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
172-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
171+
data: t.Union[str, list[str], "Mapping[str, str]"],
172+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
173173
) -> bool:
174174
if not isinstance(rhs, str) or not isinstance(data, (str, Mapping, list)):
175175
return False
@@ -178,8 +178,8 @@ def lookup_contains(
178178

179179

180180
def lookup_icontains(
181-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
182-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
181+
data: t.Union[str, list[str], "Mapping[str, str]"],
182+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
183183
) -> bool:
184184
if not isinstance(rhs, str) or not isinstance(data, (str, Mapping, list)):
185185
return False
@@ -193,8 +193,8 @@ def lookup_icontains(
193193

194194

195195
def lookup_startswith(
196-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
197-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
196+
data: t.Union[str, list[str], "Mapping[str, str]"],
197+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
198198
) -> bool:
199199
if not isinstance(rhs, str) or not isinstance(data, str):
200200
return False
@@ -203,8 +203,8 @@ def lookup_startswith(
203203

204204

205205
def lookup_istartswith(
206-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
207-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
206+
data: t.Union[str, list[str], "Mapping[str, str]"],
207+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
208208
) -> bool:
209209
if not isinstance(rhs, str) or not isinstance(data, str):
210210
return False
@@ -213,8 +213,8 @@ def lookup_istartswith(
213213

214214

215215
def lookup_endswith(
216-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
217-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
216+
data: t.Union[str, list[str], "Mapping[str, str]"],
217+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
218218
) -> bool:
219219
if not isinstance(rhs, str) or not isinstance(data, str):
220220
return False
@@ -223,17 +223,17 @@ def lookup_endswith(
223223

224224

225225
def lookup_iendswith(
226-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
227-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
226+
data: t.Union[str, list[str], "Mapping[str, str]"],
227+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
228228
) -> bool:
229229
if not isinstance(rhs, str) or not isinstance(data, str):
230230
return False
231231
return data.lower().endswith(rhs.lower())
232232

233233

234234
def lookup_in(
235-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
236-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
235+
data: t.Union[str, list[str], "Mapping[str, str]"],
236+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
237237
) -> bool:
238238
if isinstance(rhs, list):
239239
return data in rhs
@@ -254,8 +254,8 @@ def lookup_in(
254254

255255

256256
def lookup_nin(
257-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
258-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
257+
data: t.Union[str, list[str], "Mapping[str, str]"],
258+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
259259
) -> bool:
260260
if isinstance(rhs, list):
261261
return data not in rhs
@@ -276,17 +276,17 @@ def lookup_nin(
276276

277277

278278
def lookup_regex(
279-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
280-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
279+
data: t.Union[str, list[str], "Mapping[str, str]"],
280+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
281281
) -> bool:
282282
if isinstance(data, (str, bytes, re.Pattern)) and isinstance(rhs, (str, bytes)):
283283
return bool(re.search(rhs, data))
284284
return False
285285

286286

287287
def lookup_iregex(
288-
data: t.Union[str, t.List[str], "Mapping[str, str]"],
289-
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
288+
data: t.Union[str, list[str], "Mapping[str, str]"],
289+
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
290290
) -> bool:
291291
if isinstance(data, (str, bytes, re.Pattern)) and isinstance(rhs, (str, bytes)):
292292
return bool(re.search(rhs, data, re.IGNORECASE))
@@ -320,7 +320,7 @@ def __init__(self, op: str, *args: object) -> None:
320320
return super().__init__(f"{op} not in LOOKUP_NAME_MAP")
321321

322322

323-
class QueryList(t.List[T], t.Generic[T]):
323+
class QueryList(list[T], t.Generic[T]):
324324
"""Filter list of object/dictionaries. For small, local datasets.
325325
326326
*Experimental, unstable*.
@@ -475,7 +475,7 @@ class QueryList(t.List[T], t.Generic[T]):
475475
def __init__(self, items: t.Optional["Iterable[T]"] = None) -> None:
476476
super().__init__(items if items is not None else [])
477477

478-
def items(self) -> t.List[t.Tuple[str, T]]:
478+
def items(self) -> list[tuple[str, T]]:
479479
if self.pk_key is None:
480480
raise PKRequiredException
481481
return [(getattr(item, self.pk_key), item) for item in self]
@@ -531,19 +531,19 @@ def filter_lookup(obj: t.Any) -> bool:
531531
return True
532532

533533
if callable(matcher):
534-
_filter = matcher
534+
filter_ = matcher
535535
elif matcher is not None:
536536

537-
def val_match(obj: t.Union[str, t.List[t.Any], T]) -> bool:
537+
def val_match(obj: t.Union[str, list[t.Any], T]) -> bool:
538538
if isinstance(matcher, list):
539539
return obj in matcher
540540
return bool(obj == matcher)
541541

542-
_filter = val_match
542+
filter_ = val_match
543543
else:
544-
_filter = filter_lookup
544+
filter_ = filter_lookup
545545

546-
return self.__class__(k for k in self if _filter(k))
546+
return self.__class__(k for k in self if filter_(k))
547547

548548
def get(
549549
self,

src/libtmux/_vendor/version.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@
1212
import collections
1313
import itertools
1414
import re
15-
from typing import Callable, Optional, SupportsInt, Tuple, Union
15+
from typing import Callable, Optional, SupportsInt, Union
1616

1717
from ._structures import Infinity, InfinityType, NegativeInfinity, NegativeInfinityType
1818

1919
__all__ = ["VERSION_PATTERN", "InvalidVersion", "Version", "parse"]
2020

2121
InfiniteTypes = Union[InfinityType, NegativeInfinityType]
22-
PrePostDevType = Union[InfiniteTypes, Tuple[str, int]]
22+
PrePostDevType = Union[InfiniteTypes, tuple[str, int]]
2323
SubLocalType = Union[InfiniteTypes, int, str]
2424
LocalType = Union[
2525
NegativeInfinityType,
26-
Tuple[
26+
tuple[
2727
Union[
2828
SubLocalType,
29-
Tuple[SubLocalType, str],
30-
Tuple[NegativeInfinityType, SubLocalType],
29+
tuple[SubLocalType, str],
30+
tuple[NegativeInfinityType, SubLocalType],
3131
],
3232
...,
3333
],
3434
]
35-
CmpKey = Tuple[
35+
CmpKey = tuple[
3636
int,
37-
Tuple[int, ...],
37+
tuple[int, ...],
3838
PrePostDevType,
3939
PrePostDevType,
4040
PrePostDevType,
@@ -293,11 +293,11 @@ def epoch(self) -> int:
293293
>>> Version("1!2.0.0").epoch
294294
1
295295
"""
296-
_epoch: int = self._version.epoch
297-
return _epoch
296+
epoch: int = self._version.epoch
297+
return epoch
298298

299299
@property
300-
def release(self) -> Tuple[int, ...]:
300+
def release(self) -> tuple[int, ...]:
301301
"""The components of the "release" segment of the version.
302302
303303
>>> Version("1.2.3").release
@@ -310,11 +310,11 @@ def release(self) -> Tuple[int, ...]:
310310
Includes trailing zeroes but not the epoch or any pre-release / development /
311311
post-release suffixes.
312312
"""
313-
_release: Tuple[int, ...] = self._version.release
314-
return _release
313+
release: tuple[int, ...] = self._version.release
314+
return release
315315

316316
@property
317-
def pre(self) -> Optional[Tuple[str, int]]:
317+
def pre(self) -> Optional[tuple[str, int]]:
318318
"""The pre-release segment of the version.
319319
320320
>>> print(Version("1.2.3").pre)
@@ -326,8 +326,8 @@ def pre(self) -> Optional[Tuple[str, int]]:
326326
>>> Version("1.2.3rc1").pre
327327
('rc', 1)
328328
"""
329-
_pre: Optional[Tuple[str, int]] = self._version.pre
330-
return _pre
329+
pre: Optional[tuple[str, int]] = self._version.pre
330+
return pre
331331

332332
@property
333333
def post(self) -> Optional[int]:
@@ -476,7 +476,7 @@ def micro(self) -> int:
476476
def _parse_letter_version(
477477
letter: str,
478478
number: Union[str, bytes, SupportsInt],
479-
) -> Optional[Tuple[str, int]]:
479+
) -> Optional[tuple[str, int]]:
480480
if letter:
481481
# We consider there to be an implicit 0 in a pre-release if there is
482482
# not a numeral associated with it.
@@ -524,18 +524,18 @@ def _parse_local_version(local: str) -> Optional[LocalType]:
524524

525525
def _cmpkey(
526526
epoch: int,
527-
release: Tuple[int, ...],
528-
pre: Optional[Tuple[str, int]],
529-
post: Optional[Tuple[str, int]],
530-
dev: Optional[Tuple[str, int]],
531-
local: Optional[Tuple[SubLocalType]],
527+
release: tuple[int, ...],
528+
pre: Optional[tuple[str, int]],
529+
post: Optional[tuple[str, int]],
530+
dev: Optional[tuple[str, int]],
531+
local: Optional[tuple[SubLocalType]],
532532
) -> CmpKey:
533533
# When we compare a release version, we want to compare it with all of the
534534
# trailing zeros removed. So we'll use a reverse the list, drop all the now
535535
# leading zeros until we come to something non zero, then take the rest
536536
# re-reverse it back into the correct order and make it a tuple and use
537537
# that for our sorting key.
538-
_release = tuple(
538+
release_ = tuple(
539539
reversed(list(itertools.dropwhile(lambda x: x == 0, reversed(release)))),
540540
)
541541

@@ -544,31 +544,31 @@ def _cmpkey(
544544
# if there is not a pre or a post segment. If we have one of those then
545545
# the normal sorting rules will handle this case correctly.
546546
if pre is None and post is None and dev is not None:
547-
_pre: PrePostDevType = NegativeInfinity
547+
pre_: PrePostDevType = NegativeInfinity
548548
# Versions without a pre-release (except as noted above) should sort after
549549
# those with one.
550550
elif pre is None:
551-
_pre = Infinity
551+
pre_ = Infinity
552552
else:
553-
_pre = pre
553+
pre_ = pre
554554

555555
# Versions without a post segment should sort before those with one.
556556
if post is None:
557-
_post: PrePostDevType = NegativeInfinity
557+
post_: PrePostDevType = NegativeInfinity
558558

559559
else:
560-
_post = post
560+
post_ = post
561561

562562
# Versions without a development segment should sort after those with one.
563563
if dev is None:
564-
_dev: PrePostDevType = Infinity
564+
dev_: PrePostDevType = Infinity
565565

566566
else:
567-
_dev = dev
567+
dev_ = dev
568568

569569
if local is None:
570570
# Versions without a local segment should sort before those with one.
571-
_local: LocalType = NegativeInfinity
571+
local_: LocalType = NegativeInfinity
572572
else:
573573
# Versions with a local segment need that segment parsed to implement
574574
# the sorting rules in PEP440.
@@ -577,8 +577,8 @@ def _cmpkey(
577577
# - Numeric segments sort numerically
578578
# - Shorter versions sort before longer versions when the prefixes
579579
# match exactly
580-
_local = tuple(
580+
local_ = tuple(
581581
(i, "") if isinstance(i, int) else (NegativeInfinity, i) for i in local
582582
)
583583

584-
return epoch, _release, _pre, _post, _dev, _local
584+
return epoch, release_, pre_, post_, dev_, local_

0 commit comments

Comments
 (0)