Skip to content

Fix CLI declarations that disagree with runtime behaviour - #1082

Open
tony wants to merge 3 commits into
class-variablesfrom
cli-annotation-fixes
Open

Fix CLI declarations that disagree with runtime behaviour#1082
tony wants to merge 3 commits into
class-variablesfrom
cli-annotation-fixes

Conversation

@tony

@tony tony commented Jul 26, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix --quiet and --force help strings in tmuxp freeze, both of which described behaviour the flags do not have
  • Fix CLIFreezeNamespace.save_to, typed str | None while -o/--save-to parses with type=pathlib.Path
  • Fix CLIColorsLiteral, which admitted 56 (a value nothing produces) and excluded 256 (the value -2 assigns)
  • Remove three namespace annotations declared for flags that do not exist

Each was found while documenting these classes: writing an accurate description of a field is what exposed that the field's declaration and its runtime behaviour disagreed.

Based on class-variables, which supplies the docstrings these declarations belong to.

Changes

src/tmuxp/cli/freeze.py

--quiet: help said "don't prompt for confirmation". The flag only guards informational output — every if not args.quiet wraps a tmuxp_echo call. Confirmation prompts still run; --yes is the flag that skips them. A user reaching for -q to get an unattended freeze would still be sitting at a prompt.

--force: help said "overwrite the workspace file". It only relaxes the existence check inside the interactive destination prompt (if not args.force and os.path.exists(dest_prompt)). When -o is given there is no existence check at all, so --force is a no-op on the path most users pair it with.

save_to: declared str | None, but argparse stores a PosixPath. Correcting the annotation surfaced three genuine type errors that the wrong declaration had been masking — the destination is funnelled through a local that becomes a str. That conversion is now explicit at the boundary.

src/tmuxp/cli/load.py

CLIColorsLiteral was Literal[56, 88]. -2 stores const=256 and -8 stores const=88, so the type admitted a value nothing produces and rejected one of the two the flags actually assign. 56 reads as a dropped digit from 256.

src/tmuxp/cli/shell.py, src/tmuxp/cli/__init__.py

CLIShellNamespace.colors and .log_file are declared, but the shell subparser defines no -2/-8 and no --log-file, and command_shell reads neither. CLINamespace.version is declared, but --version uses argparse's version action, which prints and exits with dest suppressed. All three are absent from the parsed namespace.

Verification

Confirm -2 yields the value the corrected literal admits:

$ python -c "from tmuxp.cli import create_parser; print(create_parser().parse_args(['load','x','-2']).colors)"

Confirm the removed annotations never had a value:

$ python -c "from tmuxp.cli import create_parser; n=create_parser().parse_args(['shell']); print(hasattr(n,'colors'), hasattr(n,'log_file'))"

Test plan

  • test_freeze_save_to_parses_as_a_path — the parsed value is a pathlib.Path, matching the declaration
  • test_freeze_quiet_help_describes_what_it_silences — help names output suppression and points at --yes
  • test_freeze_force_help_scopes_itself_to_the_prompt — help scopes itself to the prompted destination
  • uv run ruff format / ruff check clean
  • uv run mypy src/ tests/ clean, including the three errors the corrected save_to type exposed
  • Full suite green

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.53%. Comparing base (9e6b143) to head (6338d84).

Additional details and impacted files
@@                 Coverage Diff                 @@
##           class-variables    #1082      +/-   ##
===================================================
- Coverage            82.55%   82.53%   -0.02%     
===================================================
  Files                   31       31              
  Lines                 2768     2766       -2     
  Branches               518      518              
===================================================
- Hits                  2285     2283       -2     
  Misses                 346      346              
  Partials               137      137              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony
tony force-pushed the class-variables branch from 45ee069 to 9e6b143 Compare July 27, 2026 01:42
tony added 3 commits July 26, 2026 20:42
why: Three statements freeze makes about itself were wrong. --quiet
advertised skipping confirmation, but it only gates informational
output -- confirmations still run, and --yes is what skips them.
--force advertised overwriting the workspace file, but it only
relaxes the existence check inside the interactive destination
prompt, so it does nothing when -o is given. save_to was typed
str | None while -o parses with type=pathlib.Path.

what:
- Reword the --quiet and --force help to what each one does, and
  point --quiet at --yes for the behaviour it used to claim
- Type save_to as pathlib.Path | None and convert at the one place
  the destination becomes a string
- Pin all three with tests built from create_freeze_subparser
why: CLIColorsLiteral admitted 56, a value nothing produces. The -2
flag stores 256, so the type excluded the very value its own flag
assigns and admitted one that cannot occur.

what:
- Declare CLIColorsLiteral as Literal[256, 88]
why: Three namespace fields were declared for flags that do not
exist. The shell subparser defines no -2/-8 and no --log-file, and
--version uses argparse's version action, which prints and exits
with dest suppressed. Reading any of them raises AttributeError, so
the annotations described a surface no caller could use.

what:
- Remove colors and log_file from CLIShellNamespace, and the colour
  literal left unused by their removal
- Remove version from CLINamespace
@tony
tony force-pushed the cli-annotation-fixes branch from 64cc513 to 6338d84 Compare July 27, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant