From 1bba33b34dfe8c87907950900cdf6b0454520baa Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 31 Jul 2022 13:05:27 -0500 Subject: [PATCH 1/5] chore(Window): Add session / server instance typings --- libtmux/window.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libtmux/window.py b/libtmux/window.py index c70440df9..affd4933c 100644 --- a/libtmux/window.py +++ b/libtmux/window.py @@ -18,6 +18,10 @@ ) from .pane import Pane +if t.TYPE_CHECKING: + from .server import Server + from .session import Session + logger = logging.getLogger(__name__) @@ -41,16 +45,16 @@ class Window(TmuxMappingObject, TmuxRelationalObject): https://man.openbsd.org/tmux.1#DESCRIPTION. Accessed April 1st, 2018. """ - #: unique child ID key for :class:`~libtmux.common.TmuxRelationalObject` child_id_attribute = "pane_id" - #: namespace used :class:`~libtmux.common.TmuxMappingObject` + """Unique child ID key for :class:`~libtmux.common.TmuxRelationalObject`""" formatter_prefix = "window_" + """Namespace used for :class:`~libtmux.common.TmuxMappingObject`""" + server: "Server" + """:class:`libtmux.Server` window is linked to""" + session: "Session" + """:class:`libtmux.Session` window is linked to""" - def __init__(self, session=None, **kwargs): - - if not session: - raise ValueError("Window requires a Session, session=Session") - + def __init__(self, session: "Session", **kwargs): self.session = session self.server = self.session.server From 9c58e0f35f2ae1586f951a1e565c62a03dfe490d Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 31 Jul 2022 13:11:51 -0500 Subject: [PATCH 2/5] chore(Session): Add server instance for typings --- libtmux/session.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libtmux/session.py b/libtmux/session.py index e5299fc83..4b23cc46e 100644 --- a/libtmux/session.py +++ b/libtmux/session.py @@ -22,6 +22,7 @@ if t.TYPE_CHECKING: from .pane import Pane + from .server import Server logger = logging.getLogger(__name__) @@ -50,12 +51,14 @@ class Session(TmuxMappingObject, TmuxRelationalObject, EnvironmentMixin): https://man.openbsd.org/tmux.1#DESCRIPTION. Accessed April 1st, 2018. """ - #: unique child ID key for :class:`~libtmux.common.TmuxRelationalObject` child_id_attribute = "window_id" - #: namespace used :class:`~libtmux.common.TmuxMappingObject` + """Unique child ID key for :class:`~libtmux.common.TmuxRelationalObject`""" formatter_prefix = "session_" + """Namespace used for :class:`~libtmux.common.TmuxMappingObject`""" + server: "Server" + """:class:`libtmux.server.Server` session is linked to""" - def __init__(self, server=None, **kwargs): + def __init__(self, server: "Server", **kwargs): EnvironmentMixin.__init__(self) self.server = server From 013f1a99080c097f7ec439419f0e889ac7126e2b Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 31 Jul 2022 13:13:42 -0500 Subject: [PATCH 3/5] chore(Pane): Add window, session, server instance for typings --- libtmux/pane.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/libtmux/pane.py b/libtmux/pane.py index e35a70f65..d944105fe 100644 --- a/libtmux/pane.py +++ b/libtmux/pane.py @@ -6,10 +6,17 @@ """ import logging +import typing as t from . import exc from .common import TmuxMappingObject, TmuxRelationalObject +if t.TYPE_CHECKING: + from .server import Server + from .session import Session + from .window import Window + + logger = logging.getLogger(__name__) @@ -20,7 +27,7 @@ class Pane(TmuxMappingObject, TmuxRelationalObject): ``Pane`` instances can send commands directly to a pane, or traverse between linked tmux objects. - Parameters + Attributes ---------- window : :class:`Window` @@ -42,13 +49,16 @@ class Pane(TmuxMappingObject, TmuxRelationalObject): Accessed April 1st, 2018. """ - #: namespace used :class:`~libtmux.common.TmuxMappingObject` formatter_prefix = "pane_" - - def __init__(self, window=None, **kwargs): - if not window: - raise ValueError("Pane must have ``Window`` object") - + """Namespace used for :class:`~libtmux.common.TmuxMappingObject`""" + window: "Window" + """:class:`libtmux.Window` pane is linked to""" + session: "Session" + """:class:`libtmux.Session` pane is linked to""" + server: "Server" + """:class:`libtmux.Server` pane is linked to""" + + def __init__(self, window: "Window", **kwargs): self.window = window self.session = self.window.session self.server = self.session.server @@ -275,7 +285,10 @@ def select_pane(self) -> "Pane": ------- :class:`pane` """ - return self.window.select_pane(self.get("pane_id")) + pane = self.window.select_pane(self._pane_id) + if pane is None: + raise exc.LibTmuxException(f"Pane not found: {self}") + return pane def __repr__(self) -> str: return "{}({} {})".format( From 09c34badf500800dfd2af771a10659d453596247 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 31 Jul 2022 13:39:41 -0500 Subject: [PATCH 4/5] chore(Server): Fix docstrings --- libtmux/server.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libtmux/server.py b/libtmux/server.py index d1301aa30..d31f39296 100644 --- a/libtmux/server.py +++ b/libtmux/server.py @@ -60,18 +60,18 @@ class Server(TmuxRelationalObject, EnvironmentMixin): Accessed April 1st, 2018. """ - #: ``[-L socket-name]`` socket_name = None - #: ``[-S socket-path]`` + """Passthrough to ``[-L socket-name]``""" socket_path = None - #: ``[-f file]`` + """Passthrough to ``[-S socket-path]``""" config_file = None - #: ``-2`` or ``-8`` + """Passthrough to ``[-f file]``""" colors = None - #: unique child ID used by :class:`~libtmux.common.TmuxRelationalObject` + """``-2`` or ``-8``""" child_id_attribute = "session_id" - #: namespace used :class:`~libtmux.common.TmuxMappingObject` + """Unique child ID used by :class:`~libtmux.common.TmuxRelationalObject`""" formatter_prefix = "server_" + """Namespace used for :class:`~libtmux.common.TmuxMappingObject`""" def __init__( self, From e5ef48ee260f12ff75eed7983777788b29450764 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 31 Jul 2022 13:32:36 -0500 Subject: [PATCH 5/5] docs(CHANGES): Add the typings --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index a83bdcef4..9462f6e03 100644 --- a/CHANGES +++ b/CHANGES @@ -29,6 +29,9 @@ $ pip install --user --upgrade --pre libtmux This created issues with running poetry while inside the virtualenv. +- Typings + - Core level relations, e.g. `Pane.window`, `Pane.session`, `Pane.server`, `Window.server` {issue}`385` + ### Documentation - Renewed logo