Fix negative_option conflict in NESTED argument generation mode - #365
Open
Sanjays2402 wants to merge 1 commit into
Open
Fix negative_option conflict in NESTED argument generation mode#365Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #364
With
ArgumentGenerationMode.NESTED, option strings are built from the field'sdestinstead ofprefix, soprefixstays empty and the explicitnegative_optionnever got a disambiguating prefix — adding the same dataclass twice made both fields emit the same negative flag and argparse raisedconflicting option string: --sym.negative_option_prefixnow falls back to the dotted part of the generated option string whenprefixis empty; FLAT mode is unchanged.Regression test added next to
test_nested_bool_field_negative_option_conflictintest/test_bools.py: it fails withArgumentErrorwithout the fix and passes with it.This change was prepared with AI assistance; the regression test was run locally and fails without the fix.