This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author a.badger
Recipients a.badger
Date 2021-07-09.05:07:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This is related to but a different symptom (and the current proposed fix for 38956 will not fix this.  My proposed fixes for this would also fix 38956).

I have the following code which uses BooleanOptionalAction along with a default of SUPPRESS (I use SUPPRESS because I merge these with settings from config and environment variables and then validate and add default values using a schema.  SUPPRESS allows me to tell when a value was not specified at the command line by the user):

                                   dest='indexes', action=BooleanOptionalAction,    

That code outputs:

  --indexes, --no-indexes
                        Test (default: ==SUPPRESS==)

Similar code that does not use BooleanOptionalAction does not show default: ==SUPPRESS == even when formatter_class=ArgumentDefaultsHelpFormatter is used.

Looking at the code, this is occurring because BooleanOptionalArgument has its own code to add default: on its own (instead of leaving formatting as the responsibility of the formatter_class). The code in BooleanOptionalArgument handles less cases where the default should be skipped than the ArgumentDefaultsHelpFormatter code; SUPPRESS is one of the missing cases.

I can see two ways of fixing this:

(1) Remove the code from BooleanOptionalArgument that adds the default values.  It seems to violate the architecture of argparse which delegates modifications to the help message to the formatter_class so this is a special case which could cause issues for future modifications as well.

(2) If the usefulness of outputting the default values without changing the formatter_class is deemed too important to relinquish, then moving the code that ArgumentDefaultsHelpFormatter uses to determine when to skip adding default to the help message can be extracted from ArgumentDefaultsHelpFormatter and called by both ArgumentDefaultsHelpFormatter and BooleanOptionalArgument .

In a review of a fix for raymond hettinger thought that outputting of the default values was important to keep although I'm not clear on whether he considered that the usefulness comes at the price of possibly violating argparse's architecture.  If he hasn't changed his mind, then #2 is probably the way to resolve this.

I can submit a PR for either of these once I know which direction to take (the first is just removing a few lines of code and I've already written the second one since it seemed like the direction that raymond had last asked for).

Please let me know how you'd like me to proceed.
Date User Action Args
2021-07-09 05:07:37a.badgersetrecipients: + a.badger
2021-07-09 05:07:37a.badgersetmessageid: <>
2021-07-09 05:07:37a.badgerlinkissue44587 messages
2021-07-09 05:07:36a.badgercreate