Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable abbreviations on internal parser. #477

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pydantic_settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ def __init__(
description=None if settings_cls.__doc__ is None else dedent(settings_cls.__doc__),
formatter_class=formatter_class,
prefix_chars=self.cli_flag_prefix_char,
allow_abbrev=False,
)
if root_parser is None
else root_parser
Expand Down
14 changes: 14 additions & 0 deletions tests/test_source_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2223,3 +2223,17 @@ class SettingsInvalidReqCircleReqField(BaseModel):

with pytest.raises(ValueError, match='mutually exclusive arguments must be optional'):
CliApp.run(SettingsInvalidReqCircleReqField)


def test_cli_invalid_abbrev():
class MySettings(BaseSettings):
bacon: str = ''
badger: str = ''

with pytest.raises(
SettingsError,
match='error parsing CLI: unrecognized arguments: --bac cli abbrev are invalid for internal parser',
):
CliApp.run(
MySettings, cli_args=['--bac', 'cli abbrev are invalid for internal parser'], cli_exit_on_error=False
)
Loading