Skip to content

Commit ffc05ed

Browse files
committed
ControlModeEngine(types): Extend process protocol (pid/poll)
why: mypy flagged pid/poll usage and FakeProcess stubs; protocol needs those attributes. what: - Add pid and poll to _ControlProcess protocol to match Popen/fakes - Update test fakes to implement protocol directly (no casts) - Keep ruff/mypy clean without ignores
1 parent 22c456a commit ffc05ed

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/libtmux/_internal/engines/control_mode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ class _ControlProcess(t.Protocol):
3434
stdin: t.TextIO | None
3535
stdout: t.Iterable[str] | None
3636
stderr: t.Iterable[str] | None
37+
pid: int | None
3738

3839
def terminate(self) -> None: ...
3940

4041
def kill(self) -> None: ...
4142

4243
def wait(self, timeout: float | None = None) -> t.Any: ...
4344

45+
def poll(self) -> int | None: ...
46+
4447

4548
class _ProcessFactory(t.Protocol):
4649
"""Protocol for constructing a control-mode process."""

tests/test_control_mode_engine.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import io
66
import pathlib
7-
import subprocess
87
import time
98
import typing as t
109

@@ -86,6 +85,7 @@ def __init__(self) -> None:
8685
self.stdout = BlockingStdout()
8786
self.stderr = None
8887
self._terminated = False
88+
self.pid = 1234
8989

9090
def terminate(self) -> None: # pragma: no cover - simple stub
9191
self._terminated = True
@@ -96,14 +96,17 @@ def kill(self) -> None: # pragma: no cover - simple stub
9696
def wait(self, timeout: float | None = None) -> None: # pragma: no cover
9797
return None
9898

99+
def poll(self) -> int | None: # pragma: no cover - simple stub
100+
return 0
101+
99102
engine = ControlModeEngine(command_timeout=0.01)
100103

101104
fake_process = FakeProcess()
102105

103106
def fake_start(server_args: t.Sequence[str | int] | None) -> None:
104107
engine.tmux_bin = "tmux"
105108
engine._server_args = tuple(server_args or ())
106-
engine.process = t.cast(subprocess.Popen[str], fake_process)
109+
engine.process = fake_process
107110

108111
monkeypatch.setattr(engine, "_start_process", fake_start)
109112

@@ -122,6 +125,7 @@ def __init__(self) -> None:
122125
self.stdout: t.Iterator[str] = iter([]) # no output
123126
self.stderr = None
124127
self._terminated = False
128+
self.pid = 5678
125129

126130
def terminate(self) -> None:
127131
self._terminated = True
@@ -132,12 +136,15 @@ def kill(self) -> None:
132136
def wait(self, timeout: float | None = None) -> None:
133137
return None
134138

139+
def poll(self) -> int | None:
140+
return 0
141+
135142
engine = ControlModeEngine(command_timeout=5.0)
136143

137144
def fake_start(server_args: t.Sequence[str | int] | None) -> None:
138145
engine.tmux_bin = "tmux"
139146
engine._server_args = tuple(server_args or ())
140-
engine.process = t.cast(subprocess.Popen[str], FakeProcess())
147+
engine.process = FakeProcess()
141148

142149
monkeypatch.setattr(engine, "_start_process", fake_start)
143150

@@ -243,6 +250,7 @@ class FakeProcess:
243250
def __init__(self) -> None:
244251
self.stdin = FakeStdin()
245252
self._terminated = False
253+
self.pid = 9999
246254

247255
def terminate(self) -> None:
248256
self._terminated = True
@@ -253,8 +261,11 @@ def kill(self) -> None: # pragma: no cover - simple stub
253261
def wait(self, timeout: float | None = None) -> None:
254262
return None
255263

264+
def poll(self) -> int | None:
265+
return 0
266+
256267
engine = ControlModeEngine()
257-
engine.process = FakeProcess() # type: ignore[assignment]
268+
engine.process = FakeProcess()
258269

259270
with pytest.raises(case.should_raise):
260271
engine._write_line("list-sessions", server_args=())

0 commit comments

Comments
 (0)