Skip to content

Commit 5724aaf

Browse files
authored
chore: More typing improvements (#392)
Follow up to #383
2 parents b5e8be9 + b20554c commit 5724aaf

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

libtmux/common.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,7 @@ class TmuxRelationalObject(Generic[O, D]):
388388
children: t.List[O]
389389
child_id_attribute: str
390390

391-
def find_where(
392-
self, attrs: Dict[str, str]
393-
) -> Optional[Union["Pane", "Window", "Session"]]:
391+
def find_where(self, attrs: D) -> Optional[Union["Pane", "Window", "Session"]]:
394392
"""Return object on first match.
395393
396394
.. versionchanged:: 0.4
@@ -403,19 +401,18 @@ def find_where(
403401
return None
404402

405403
@overload
406-
def where(self, attrs: Dict[str, str], first: "Literal[True]") -> O:
404+
def where(self, attrs: D, first: "Literal[True]") -> O:
407405
...
408406

409407
@overload
410-
def where(self, attrs: Dict[str, str], first: "Literal[False]") -> t.List[O]:
408+
def where(self, attrs: D, first: "Literal[False]") -> t.List[O]:
411409
...
412410

413411
@overload
414-
def where(self, attrs: Dict[str, str]) -> t.List[O]:
412+
def where(self, attrs: D) -> t.List[O]:
415413
...
416414

417-
def where(self, attrs: Dict[str, str], first: bool = False) -> t.Union[List[O], O]:
418-
# ) -> List[Union["Session", "Pane", "Window", t.Any]]:
415+
def where(self, attrs: D, first: bool = False) -> t.Union[List[O], O]:
419416
"""
420417
Return objects matching child objects properties.
421418
@@ -426,7 +423,7 @@ def where(self, attrs: Dict[str, str], first: bool = False) -> t.Union[List[O],
426423
427424
Returns
428425
-------
429-
list
426+
list of objects, or one object if ``first=True``
430427
"""
431428

432429
# from https://github.com/serkanyersen/underscore.py
@@ -445,7 +442,7 @@ def by(val: O) -> bool:
445442
return target_children[0]
446443
return target_children
447444

448-
def get_by_id(self, id: str) -> Optional[Union["Pane", "Window", "Session"]]:
445+
def get_by_id(self, id: str) -> Optional[O]:
449446
"""
450447
Return object based on ``child_id_attribute``.
451448

tests/test_tmuxobject.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,21 @@ def test_get_by_id(server: Server, session: Session) -> None:
161161
for session in server.sessions:
162162
session_id = session.get("session_id")
163163
assert session_id is not None
164-
get_by_id = server.get_by_id(session_id)
164+
get_session_by_id = server.get_by_id(session_id)
165165

166-
assert get_by_id == session
167-
assert isinstance(get_by_id, Session)
166+
assert get_session_by_id == session
167+
assert isinstance(get_session_by_id, Session)
168168
assert server.get_by_id("$" + next(namer)) is None
169169

170170
# session.get_by_id
171171
for window in session.windows:
172172
window_id = window.get("window_id")
173173
assert window_id is not None
174174

175-
get_by_id = session.get_by_id(window_id)
175+
get_window_by_id = session.get_by_id(window_id)
176176

177-
assert get_by_id == window
178-
assert isinstance(get_by_id, Window)
177+
assert get_window_by_id == window
178+
assert isinstance(get_window_by_id, Window)
179179

180180
assert session.get_by_id("@" + next(namer)) is None
181181

@@ -184,8 +184,8 @@ def test_get_by_id(server: Server, session: Session) -> None:
184184
pane_id = pane.get("pane_id")
185185
assert pane_id is not None
186186

187-
get_by_id = window.get_by_id(pane_id)
187+
get_pane_by_id = window.get_by_id(pane_id)
188188

189-
assert get_by_id == pane
190-
assert isinstance(get_by_id, Pane)
189+
assert get_pane_by_id == pane
190+
assert isinstance(get_pane_by_id, Pane)
191191
assert window.get_by_id("%" + next(namer)) is None

0 commit comments

Comments
 (0)