diff --git a/libtmux/common.py b/libtmux/common.py index 333edc748..b1660a79c 100644 --- a/libtmux/common.py +++ b/libtmux/common.py @@ -388,9 +388,7 @@ class TmuxRelationalObject(Generic[O, D]): children: t.List[O] child_id_attribute: str - def find_where( - self, attrs: Dict[str, str] - ) -> Optional[Union["Pane", "Window", "Session"]]: + def find_where(self, attrs: D) -> Optional[Union["Pane", "Window", "Session"]]: """Return object on first match. .. versionchanged:: 0.4 @@ -403,19 +401,18 @@ def find_where( return None @overload - def where(self, attrs: Dict[str, str], first: "Literal[True]") -> O: + def where(self, attrs: D, first: "Literal[True]") -> O: ... @overload - def where(self, attrs: Dict[str, str], first: "Literal[False]") -> t.List[O]: + def where(self, attrs: D, first: "Literal[False]") -> t.List[O]: ... @overload - def where(self, attrs: Dict[str, str]) -> t.List[O]: + def where(self, attrs: D) -> t.List[O]: ... - def where(self, attrs: Dict[str, str], first: bool = False) -> t.Union[List[O], O]: - # ) -> List[Union["Session", "Pane", "Window", t.Any]]: + def where(self, attrs: D, first: bool = False) -> t.Union[List[O], O]: """ Return objects matching child objects properties. @@ -426,7 +423,7 @@ def where(self, attrs: Dict[str, str], first: bool = False) -> t.Union[List[O], Returns ------- - list + list of objects, or one object if ``first=True`` """ # from https://github.com/serkanyersen/underscore.py @@ -445,7 +442,7 @@ def by(val: O) -> bool: return target_children[0] return target_children - def get_by_id(self, id: str) -> Optional[Union["Pane", "Window", "Session"]]: + def get_by_id(self, id: str) -> Optional[O]: """ Return object based on ``child_id_attribute``. diff --git a/tests/test_tmuxobject.py b/tests/test_tmuxobject.py index 98e53358e..992c73d3f 100644 --- a/tests/test_tmuxobject.py +++ b/tests/test_tmuxobject.py @@ -161,10 +161,10 @@ def test_get_by_id(server: Server, session: Session) -> None: for session in server.sessions: session_id = session.get("session_id") assert session_id is not None - get_by_id = server.get_by_id(session_id) + get_session_by_id = server.get_by_id(session_id) - assert get_by_id == session - assert isinstance(get_by_id, Session) + assert get_session_by_id == session + assert isinstance(get_session_by_id, Session) assert server.get_by_id("$" + next(namer)) is None # session.get_by_id @@ -172,10 +172,10 @@ def test_get_by_id(server: Server, session: Session) -> None: window_id = window.get("window_id") assert window_id is not None - get_by_id = session.get_by_id(window_id) + get_window_by_id = session.get_by_id(window_id) - assert get_by_id == window - assert isinstance(get_by_id, Window) + assert get_window_by_id == window + assert isinstance(get_window_by_id, Window) assert session.get_by_id("@" + next(namer)) is None @@ -184,8 +184,8 @@ def test_get_by_id(server: Server, session: Session) -> None: pane_id = pane.get("pane_id") assert pane_id is not None - get_by_id = window.get_by_id(pane_id) + get_pane_by_id = window.get_by_id(pane_id) - assert get_by_id == pane - assert isinstance(get_by_id, Pane) + assert get_pane_by_id == pane + assert isinstance(get_pane_by_id, Pane) assert window.get_by_id("%" + next(namer)) is None