Skip to content

Fix negative_option conflict in NESTED argument generation mode - #365

Open
Sanjays2402 wants to merge 1 commit into
lebrice:masterfrom
Sanjays2402:fix/negative-option-nested-mode
Open

Fix negative_option conflict in NESTED argument generation mode#365
Sanjays2402 wants to merge 1 commit into
lebrice:masterfrom
Sanjays2402:fix/negative-option-nested-mode

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #364

With ArgumentGenerationMode.NESTED, option strings are built from the field's dest instead of prefix, so prefix stays empty and the explicit negative_option never got a disambiguating prefix — adding the same dataclass twice made both fields emit the same negative flag and argparse raised conflicting option string: --sym. negative_option_prefix now falls back to the dotted part of the generated option string when prefix is empty; FLAT mode is unchanged.

Regression test added next to test_nested_bool_field_negative_option_conflict in test/test_bools.py: it fails with ArgumentError without the fix and passes with it.

This change was prepared with AI assistance; the regression test was run locally and fails without the fix.

With `argument_generation_mode=ArgumentGenerationMode.NESTED`, option
strings are built from the field's `dest` rather than from `prefix`, so
`prefix` stays empty and the explicit `negative_option` passed to
`BooleanOptionalAction` never received a disambiguating prefix. Adding
the same dataclass twice then made both fields generate the identical
negative flag and argparse raised `conflicting option string`.

`FieldWrapper.negative_option_prefix` now falls back to the dotted
portion of the generated option string when `prefix` is empty, so the
negative flags get the same prefix as the positive ones. FLAT mode
behaviour is unchanged.

Closes lebrice#364
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.

negative_option with argument_generation_mode=ArgumentGenerationMode.NESTED cannot resolve conflicts

1 participant