Skip to content

Commit e672929

Browse files
committed
neo(docs[fetch_objs]): Add NumPy-style docstring with doctest
why: CLAUDE.md requires NumPy-style docstrings for all functions; fetch_objs() was modified in this branch but only had a one-liner. what: - Add Parameters, Returns, Raises, and Examples sections - Add working doctest using server fixture
1 parent c414ba4 commit e672929

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/libtmux/neo.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,44 @@ def fetch_objs(
242242
list_cmd: ListCmd,
243243
list_extra_args: ListExtraArgs = None,
244244
) -> OutputsRaw:
245-
"""Fetch a listing of raw data from a tmux command."""
245+
"""Fetch a listing of raw data from a tmux command.
246+
247+
Runs a tmux list command (e.g. ``list-sessions``) with the format string
248+
from :func:`get_output_format` and parses each line of output into a dict.
249+
250+
Parameters
251+
----------
252+
server : :class:`~libtmux.server.Server`
253+
The tmux server to query.
254+
list_cmd : ListCmd
255+
The tmux list command to run, e.g. ``"list-sessions"``,
256+
``"list-windows"``, or ``"list-panes"``.
257+
list_extra_args : ListExtraArgs, optional
258+
Extra arguments appended to the tmux command (e.g. ``("-a",)``
259+
for all windows/panes, or ``["-t", session_id]`` to filter).
260+
261+
Returns
262+
-------
263+
OutputsRaw
264+
A list of dicts, each mapping tmux format field names to their
265+
non-empty string values.
266+
267+
Raises
268+
------
269+
:exc:`~libtmux.exc.LibTmuxException`
270+
If the tmux command writes to stderr.
271+
272+
Examples
273+
--------
274+
>>> from libtmux.neo import fetch_objs
275+
>>> objs = fetch_objs(server=server, list_cmd="list-sessions")
276+
>>> isinstance(objs, list)
277+
True
278+
>>> isinstance(objs[0], dict)
279+
True
280+
>>> 'session_id' in objs[0]
281+
True
282+
"""
246283
_fields, format_string = get_output_format()
247284

248285
cmd_args: list[str | int] = []

src/libtmux/server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ def new_session(
578578
raise exc.LibTmuxException(proc.stderr)
579579

580580
if not proc.stdout:
581-
raise exc.LibTmuxException("new-session produced no output")
581+
msg = "new-session produced no output"
582+
raise exc.LibTmuxException(msg)
582583

583584
session_stdout = proc.stdout[0]
584585

0 commit comments

Comments
 (0)