Skip to content

Patch default help for user provided _CliInternalArgParser#864

Closed
grabear wants to merge 2 commits into
pydantic:mainfrom
grabear:cli_patch_default_help
Closed

Patch default help for user provided _CliInternalArgParser#864
grabear wants to merge 2 commits into
pydantic:mainfrom
grabear:cli_patch_default_help

Conversation

@grabear

@grabear grabear commented May 12, 2026

Copy link
Copy Markdown

In my project we use _CliInternalArgParser directly with add_help=True, which causes an argparse error:

argparse.ArgumentError: argument -h/--help: conflicting option strings: -h, --help

This patch checks the registered actions for the argparse._HelpAction type, to prevent the issue.

To reproduce this error:

from pydantic_settings.sources.providers.cli import _CliInternalArgParser
from pydantic_settings import CliSettingsSource
from pydantic import BaseModel

CliSettingsSource(root_parser=_CliInternalArgParser(add_help=True), settings_cls=type("Model", (BaseModel,), {}))

Selected Reviewer: @samuelcolvin

…provides a _CliInternalArgParser root_parser.
@hramezani

Copy link
Copy Markdown
Collaborator

Thanks @grabear for the PR. Please fix the lint error and add a test.

@kschwab Could you please review it?

@grabear

grabear commented May 12, 2026

Copy link
Copy Markdown
Author

@hramezani @kschwab fixed it!

@hramezani

Copy link
Copy Markdown
Collaborator

@hramezani @kschwab fixed it!

please add test

@hramezani

Copy link
Copy Markdown
Collaborator

Closing due to inactivity

@hramezani hramezani closed this Jun 16, 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.

3 participants