From 276b441616ca1de5cab6556699ef9e9066338464 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 21 Nov 2026 12:44:50 -0600 Subject: [PATCH 1/4] neo(fix[parse_output]): Keep empty tmux fields as empty strings why: parse_output dropped every empty value, so a field tmux reports as empty read as None, the same as a field tmux was never asked for, and refresh() kept the old value of a field tmux had emptied. what: - Return every requested field from parse_output, "" when empty - Test a cleared pane title after refresh() and on a new object - Update the parse_output doctest --- src/libtmux/neo.py | 16 ++++++++++++---- tests/test_neo.py | 24 ++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/libtmux/neo.py b/src/libtmux/neo.py index e3ef15ec7a..645ad1a653 100644 --- a/src/libtmux/neo.py +++ b/src/libtmux/neo.py @@ -1013,7 +1013,8 @@ def parse_output( Returns ------- OutputRaw - A dict mapping field names to non-empty string values. + A dict mapping every requested field name to its value. A field tmux + reports as empty is ``""``; a field that was not requested is absent. Examples -------- @@ -1029,7 +1030,15 @@ def parse_output( ... ) >>> result['session_id'] '$1' - >>> 'pane_id' in result + + A requested field tmux left empty is an empty string: + + >>> result['session_name'] + '' + + A field the listing does not request is absent: + + >>> 'client_name' in result False """ formats, _ = get_output_format(list_cmd, tmux_version) @@ -1039,8 +1048,7 @@ def parse_output( if values and values[-1] == "": values = values[:-1] - formatter = dict(zip(formats, values, strict=True)) - return {k: v for k, v in formatter.items() if v} + return dict(zip(formats, values, strict=True)) def _split_records(stdout: list[str], field_count: int) -> list[str]: diff --git a/tests/test_neo.py b/tests/test_neo.py index 1d9cf298f6..c88e6353fb 100644 --- a/tests/test_neo.py +++ b/tests/test_neo.py @@ -27,6 +27,10 @@ _token_scope, get_output_format, ) +from libtmux.pane import Pane + +if t.TYPE_CHECKING: + from libtmux.session import Session if t.TYPE_CHECKING: from libtmux.session import Session @@ -334,7 +338,7 @@ def test_split_records_handles_no_objects() -> None: def test_refresh_clears_a_field_tmux_emptied(session: Session) -> None: - """A field tmux reports as empty stops holding its earlier value.""" + """A field tmux reports as empty reads ``""`` after a refresh.""" pane = session.active_window.active_pane assert pane is not None @@ -344,4 +348,20 @@ def test_refresh_clears_a_field_tmux_emptied(session: Session) -> None: pane.cmd("select-pane", "-T", "") pane.refresh() - assert pane.pane_title is None + assert pane.pane_title == "" + + +def test_empty_field_is_an_empty_string(session: Session) -> None: + """A field tmux reports as empty is ``""``; ``None`` means it was not asked.""" + window = session.active_window + pane = window.active_pane + assert pane is not None + + pane.set_title("titled") + pane.set_title("") + pane.refresh() + assert pane.pane_title == "" + + fresh = Pane.from_pane_id(server=session.server, pane_id=str(pane.pane_id)) + assert fresh.pane_title == "" + assert fresh.session_name == session.session_name From 95c60a3029895d0d545d424a31dd4392536856d1 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 21 Nov 2026 18:11:35 -0600 Subject: [PATCH 2/4] CHANGES(docs): Empty tmux fields read as "" why: An empty field and a field tmux was never asked for both read as None, and callers need to know the first now reads as "". what: - Add a Breaking changes entry for empty fields, with the migration --- CHANGES | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGES b/CHANGES index da57c9cda6..a97181dfbd 100644 --- a/CHANGES +++ b/CHANGES @@ -47,6 +47,24 @@ _Notes on the upcoming release will go here._ ### Breaking changes +#### Empty tmux fields read as `""` (#900) + +A field tmux reports as empty, such as a cleared +{attr}`~libtmux.Pane.pane_title`, is now the empty string, and `refresh()` +picks the change up. `None` now means only that tmux was not asked for the +field, for example one newer than the running tmux. Both cases previously read +as `None`. + +```python +# Before +if pane.pane_title is None: + ... + +# After +if not pane.pane_title: + ... +``` + #### `with Server()` no longer kills the server on exit (#728) Leaving a `with` block previously killed the {class}`~libtmux.Server`, so From 5f7795f0bfa6831201b915fca62502c8c7988b10 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Wed, 25 Nov 2026 19:18:04 -0600 Subject: [PATCH 3/4] libtmux(docs[fields]): Update Obj field docstrings and add MIGRATION note Update Session, Window, and Pane class docstrings so '' vs None matches parse_output(), add a tested MIGRATION entry for #900, and drop the duplicate TYPE_CHECKING guard in tests/test_neo.py. --- MIGRATION | 20 ++++++++++++++++++++ src/libtmux/pane.py | 3 ++- src/libtmux/session.py | 7 ++++--- src/libtmux/window.py | 3 ++- tests/test_neo.py | 3 --- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/MIGRATION b/MIGRATION index 4cde1544b4..75ce49c645 100644 --- a/MIGRATION +++ b/MIGRATION @@ -116,6 +116,26 @@ sections below for detailed migration examples and code samples. _Detailed migration steps for the next version will be posted here._ +### Empty tmux fields read as `""` (#900) + +Fields that tmux reports as empty on {class}`~libtmux.Session`, +{class}`~libtmux.Window`, {class}`~libtmux.Pane`, and {class}`~libtmux.Client` +(such as a cleared {attr}`~libtmux.Pane.pane_title` or an unset +{attr}`~libtmux.Session.session_group`) now hydrate as `""` on initial queries +and after `refresh()`. `None` is reserved for format tokens that the listing +command or running tmux version did not request. + +Replace `is None` emptiness checks with truthiness checks: + +```python +>>> _ = pane.set_title('') +>>> pane.refresh() +>>> pane.pane_title +'' +>>> not pane.pane_title +True +``` + ### Server context managers preserve the daemon (#728) Before libtmux 0.69.0, leaving a {class}`~libtmux.Server` context killed the diff --git a/src/libtmux/pane.py b/src/libtmux/pane.py index 9b104fee83..9ce595203d 100644 --- a/src/libtmux/pane.py +++ b/src/libtmux/pane.py @@ -67,7 +67,8 @@ class Pane( between linked tmux objects. **Reading it.** Every field is a tmux format token read when the pane was - listed or last refreshed, and is ``None`` when tmux gave no value. + listed or last refreshed: ``""`` when tmux reports an empty value, and + ``None`` when the listing did not request the token. :meth:`~libtmux.Pane.refresh` rewrites the fields in place and raises :exc:`~libtmux.exc.TmuxObjectDoesNotExist` when the pane has gone. The edge properties convert tmux's flags to bools. diff --git a/src/libtmux/session.py b/src/libtmux/session.py index 00518644b2..71ef527240 100644 --- a/src/libtmux/session.py +++ b/src/libtmux/session.py @@ -62,9 +62,10 @@ class Session( Holds :class:`Window` objects. **Reading it.** Every field is a tmux format token read when the session was - listed or last refreshed, and is ``None`` when tmux gave no value. - :meth:`~libtmux.Session.refresh` rewrites the fields in place and returns - ``None``. + listed or last refreshed: ``""`` when tmux reports an empty value, and + ``None`` when the listing did not request the token. + :meth:`~libtmux.Session.refresh` rewrites the fields in place and raises + :exc:`~libtmux.exc.TmuxObjectDoesNotExist` when the session has gone. - Identity: :attr:`~libtmux.Session.session_id`, :attr:`~libtmux.Session.id` diff --git a/src/libtmux/window.py b/src/libtmux/window.py index a34d147c42..ddcd815ad7 100644 --- a/src/libtmux/window.py +++ b/src/libtmux/window.py @@ -63,7 +63,8 @@ class Window( Holds :class:`Pane` objects. **Reading it.** Every field is a tmux format token read when the window was - listed or last refreshed, and is ``None`` when tmux gave no value. + listed or last refreshed: ``""`` when tmux reports an empty value, and + ``None`` when the listing did not request the token. :meth:`~libtmux.Window.refresh` rewrites the fields in place and raises :exc:`~libtmux.exc.TmuxObjectDoesNotExist` when the window has gone. diff --git a/tests/test_neo.py b/tests/test_neo.py index c88e6353fb..f4bc4d159a 100644 --- a/tests/test_neo.py +++ b/tests/test_neo.py @@ -32,9 +32,6 @@ if t.TYPE_CHECKING: from libtmux.session import Session -if t.TYPE_CHECKING: - from libtmux.session import Session - class TargetNotFoundFixture(t.NamedTuple): """One line of tmux stderr, and whether it means "that object is gone".""" From 30a010f3c38717bbbb7db4d2ab30a8cf1b035e48 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Wed, 25 Nov 2026 19:18:04 -0600 Subject: [PATCH 4/4] CHANGES(docs): Split empty-field code blocks --- CHANGES | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index a97181dfbd..60ba16680e 100644 --- a/CHANGES +++ b/CHANGES @@ -55,12 +55,16 @@ picks the change up. `None` now means only that tmux was not asked for the field, for example one newer than the running tmux. Both cases previously read as `None`. +Before: + ```python -# Before if pane.pane_title is None: ... +``` -# After +After: + +```python if not pane.pane_title: ... ```