-
-
Notifications
You must be signed in to change notification settings - Fork 113
Closed
Labels
Description
With cli_implicit_flags=True, pydantic-settings always generates both --flag and --no-flag. For some CLIs this is noisy and undesirable; we’d like a way to expose only the positive form.
Current behavior
Boolean fields become implicit flags and the help shows --flag, --no-flag (mirrors argparse’s BooleanOptionalAction).
Desired behavior
Add an opt-in switch to disable the negated form, at least at model level, with a per-field override. For example:
SettingsConfigDict(cli_boolean_negation="both" | "positive_only", ...)(default:"both"), or- a field-level annotation like
CliPositiveOnlyFlag[bool], or - a field kwarg e.g.
Field(cli_negation=False).
Why
- Cleaner help (
-v | --versionwithout--no-version). - Matches many established CLIs where only the positive form exists; reduces confusion and boilerplate in docs.
- Backward compatible if default stays as today.
Alternatives considered
Integrating a custom root parser to replace BooleanOptionalAction with store_true only for certain flags. Works, but is a workaround and leaks argparse details into user code.
References
- Docs: implicit boolean flags always generate
--flag/--no-flag. (Pydantic) - Related discussion about boolean flag UX. (GitHub)
Environment
pydantic-settings 2.11.0
Python 3.13.8
dm0, lenorakepler and Else00