Skip to content

Commit 8fdb96f

Browse files
committed
refactor(ruff,mypy) Adjust typing targets for Python 3.10
- rewrite PEP 604 unions in vendored packaging version support and tmux hydration helpers to match the new minimum - add zip(..., strict=False) wherever ruff flagged B905 in query_list and tmux formatters - trim TYPE_CHECKING fallbacks to use stdlib TypeAlias and keep typing_extensions.Self behind the guard - update tests to mirror the new 3.10 typing so mypy stays clean
1 parent a141a9b commit 8fdb96f

File tree

10 files changed

+33
-41
lines changed

10 files changed

+33
-41
lines changed

src/libtmux/_internal/query_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def __eq__(
492492
return False
493493

494494
if len(self) == len(data):
495-
for a, b in zip(self, data):
495+
for a, b in zip(self, data, strict=False):
496496
if isinstance(a, Mapping):
497497
a_keys = a.keys()
498498
if a.keys == b.keys():

src/libtmux/_internal/types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
if t.TYPE_CHECKING:
1515
from os import PathLike
16-
17-
from typing_extensions import TypeAlias
16+
from typing import TypeAlias
1817

1918
StrPath: TypeAlias = "str | PathLike[str]"

src/libtmux/_vendor/version.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121

2222
__all__ = ["VERSION_PATTERN", "InvalidVersion", "Version", "parse"]
2323

24-
InfiniteTypes = t.Union[InfinityType, NegativeInfinityType]
25-
PrePostDevType = t.Union[InfiniteTypes, tuple[str, int]]
26-
SubLocalType = t.Union[InfiniteTypes, int, str]
27-
LocalType = t.Union[
28-
NegativeInfinityType,
29-
tuple[
30-
t.Union[
31-
SubLocalType,
32-
tuple[SubLocalType, str],
33-
tuple[NegativeInfinityType, SubLocalType],
34-
],
24+
InfiniteTypes = InfinityType | NegativeInfinityType
25+
PrePostDevType = InfiniteTypes | tuple[str, int]
26+
SubLocalType = InfiniteTypes | int | str
27+
LocalType = (
28+
NegativeInfinityType
29+
| tuple[
30+
(
31+
SubLocalType
32+
| tuple[SubLocalType, str]
33+
| tuple[NegativeInfinityType, SubLocalType]
34+
),
3535
...,
36-
],
37-
]
36+
]
37+
)
3838
CmpKey = tuple[
3939
int,
4040
tuple[int, ...],

src/libtmux/neo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
if t.TYPE_CHECKING:
1515
ListCmd = t.Literal["list-sessions", "list-windows", "list-panes"]
16-
ListExtraArgs = t.Optional[Iterable[str]]
16+
ListExtraArgs = Iterable[str] | None
1717

1818
from libtmux.server import Server
1919

@@ -224,7 +224,7 @@ def fetch_objs(
224224
obj_output = proc.stdout
225225

226226
obj_formatters = [
227-
dict(zip(formats, formatter.split(FORMAT_SEPARATOR)))
227+
dict(zip(formats, formatter.split(FORMAT_SEPARATOR), strict=False))
228228
for formatter in obj_output
229229
]
230230

@@ -237,7 +237,7 @@ def fetch_obj(
237237
obj_key: str,
238238
obj_id: str,
239239
list_cmd: ListCmd = "list-panes",
240-
list_extra_args: ListExtraArgs | None = None,
240+
list_extra_args: ListExtraArgs = None,
241241
) -> OutputRaw:
242242
"""Fetch raw data from tmux command."""
243243
obj_formatters_filtered = fetch_objs(

src/libtmux/pane.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,9 @@ def split(
704704

705705
pane_output = pane_cmd.stdout[0]
706706

707-
pane_formatters = dict(zip(["pane_id"], pane_output.split(FORMAT_SEPARATOR)))
707+
pane_formatters = dict(
708+
zip(["pane_id"], pane_output.split(FORMAT_SEPARATOR), strict=False)
709+
)
708710

709711
return self.from_pane_id(server=self.server, pane_id=pane_formatters["pane_id"])
710712

src/libtmux/server.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@
3333
)
3434

3535
if t.TYPE_CHECKING:
36-
import sys
3736
import types
37+
from typing import TypeAlias
3838

39-
from libtmux._internal.types import StrPath
39+
from typing_extensions import Self
4040

41-
if sys.version_info >= (3, 10):
42-
from typing import Self, TypeAlias
43-
else:
44-
from typing_extensions import Self, TypeAlias
41+
from libtmux._internal.types import StrPath
4542

4643
DashLiteral: TypeAlias = t.Literal["-"]
4744

@@ -580,7 +577,11 @@ def new_session(
580577
os.environ["TMUX"] = env
581578

582579
session_formatters = dict(
583-
zip(["session_id"], session_stdout.split(formats.FORMAT_SEPARATOR)),
580+
zip(
581+
["session_id"],
582+
session_stdout.split(formats.FORMAT_SEPARATOR),
583+
strict=False,
584+
),
584585
)
585586

586587
return Session.from_session_id(

src/libtmux/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ def new_window(
731731
window_output = cmd.stdout[0]
732732

733733
window_formatters = dict(
734-
zip(["window_id"], window_output.split(FORMAT_SEPARATOR)),
734+
zip(["window_id"], window_output.split(FORMAT_SEPARATOR), strict=False),
735735
)
736736

737737
return Window.from_window_id(

tests/legacy_api/test_version.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@
1111
from libtmux._compat import LooseVersion
1212

1313
if t.TYPE_CHECKING:
14-
import sys
1514
from collections.abc import Callable
16-
17-
if sys.version_info >= (3, 10):
18-
from typing import TypeAlias
19-
else:
20-
from typing_extensions import TypeAlias
15+
from typing import TypeAlias
2116

2217
try:
2318
from _pytest.raises import RaisesExc

tests/test_dataclasses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from libtmux.server import Server
2323

2424
ListCmd = t.Literal["list-sessions", "list-windows", "list-panes"]
25-
ListExtraArgs = t.Optional[tuple[str]]
25+
ListExtraArgs = tuple[str] | None
2626

2727

2828
OutputRaw = dict[str, t.Any]

tests/test_version.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@
1111
from libtmux._compat import LooseVersion
1212

1313
if t.TYPE_CHECKING:
14-
import sys
1514
from collections.abc import Callable
16-
17-
if sys.version_info >= (3, 10):
18-
from typing import TypeAlias
19-
else:
20-
from typing_extensions import TypeAlias
15+
from typing import TypeAlias
2116

2217
try:
2318
from _pytest.raises import RaisesExc

0 commit comments

Comments
 (0)