Skip to content

Commit 4e36449

Browse files
committed
hooks(fix): correct show_hook return type to include SparseArray
why: Return type was incorrectly `str | int | None`, missing SparseArray what: - Fix return type to `str | int | SparseArray[str] | None` - Add comprehensive docstring with examples - Document that array hooks return SparseArray with .keys()/.values() Squash target: d4de173 (hooks feat: add bulk operations)
1 parent 565bf21 commit 4e36449

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/libtmux/hooks.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,43 @@ def show_hook(
355355
global_: bool = False,
356356
scope: OptionScope | _DefaultOptionScope | None = DEFAULT_OPTION_SCOPE,
357357
ignore_errors: bool | None = None,
358-
) -> str | int | None:
359-
"""Return value for the hook.
358+
) -> str | int | SparseArray[str] | None:
359+
"""Return value for a hook.
360+
361+
For array hooks (e.g., ``session-renamed``), returns a
362+
:class:`~libtmux._internal.sparse_array.SparseArray` with hook values
363+
at their original indices. Use ``.keys()`` for indices and ``.values()``
364+
for values.
360365
361366
Parameters
362367
----------
363368
hook : str
369+
Hook name to query
370+
371+
Returns
372+
-------
373+
str | int | SparseArray[str] | None
374+
Hook value. For array hooks, returns SparseArray.
364375
365376
Raises
366377
------
367378
:exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
368379
:exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
380+
381+
Examples
382+
--------
383+
>>> session.set_hook('session-renamed[0]', 'display-message "test"')
384+
Session($...)
385+
386+
>>> hooks = session.show_hook('session-renamed')
387+
>>> isinstance(hooks, SparseArray)
388+
True
389+
390+
>>> sorted(hooks.keys())
391+
[0]
392+
393+
>>> session.unset_hook('session-renamed')
394+
Session($...)
369395
"""
370396
hooks_output = self._show_hook(
371397
hook=hook,

0 commit comments

Comments
 (0)