Skip to content

fix: preserve store_false values in saved config files - #360

Merged
bw2 merged 2 commits into
bw2:masterfrom
jovial-liu:fix/store-false-config-roundtrip
Oct 9, 2026
Merged

bw2 merged 2 commits into
bw2:masterfrom
jovial-liu:fix/store-false-config-roundtrip

Conversation

@jovial-liu

Copy link
Copy Markdown
Contributor

Saving a store_false option supplied on the command line or through an environment variable writes its final False value as a disabled config flag. Reloading that file then restores True. Encode actual boolean values using the existing flag-invocation contract so saved settings retain their value when loaded again. Non-boolean defaults keep their existing encoding and type.

Disk round-trip regressions cover short/long aliases, environment true/false, config-sourced values, boolean defaults, an integer default, default omission and other boolean actions. The original production code fails five subtests; the fix passes all six new test methods.

Local macOS/CPython 3.12.14 validation: 1941 tests passed, 1 skipped and 5 expected failures, including the matching official CPython argparse tests. Black, strict Pydoctor, packaging and Twine checks passed. Zizmor passed in its configured offline mode with the existing suppressions. Four installed-wheel automatic save/read checks passed with -Werror. An independent public-API disk matrix improved from 110 to 135 passing cases, and four automatic save/read cases improved from one to four, with no previously passing case regressing.

Other Python versions and operating systems remain upstream CI scope. Maintainer review required by CONTRIBUTING is still pending.

AI-assisted — Tool: OpenAI Codex; model: openai/unavailable; version: unavailable.

@bw2

bw2 commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Thanks for the fix! I pushed a follow-up commit (1f90d23) on top of yours that generalizes it:

  • Flag actions (store_true, store_false, store_const) are now written as true exactly when the parsed value is the flag's const, so the config file records whether to invoke the flag. This also covers two cases the original change left out:
    • store_false options with a truthy non-boolean default (e.g. default=1 or "yes"). These were written as-is and reloaded as False.
    • store_const options. These were written as their const value (e.g. fast = fast) and failed to reload.
  • The command-line and environment-variable branches now share one helper, and both write lowercase true/false. As a result, flags that came from environment variables are now written as quoted strings in YAML/TOML output, as command-line flags already were.
  • Tests: the round-trip check now compares the types of all attributes, the non-boolean-default test covers 0, 1 and "yes", and there's a new store_const round-trip test.

One note on the PR description: "Non-boolean defaults keep their existing encoding" no longer applies. Types are still preserved on reload, but a default of 0, for example, is now written as false.

@bw2
bw2 merged commit 491a5b1 into bw2:master Oct 9, 2026
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.

2 participants