Re:Python argparse has a limitation on argument groups that ...
by dodslaser on Saturday June 14, 2025 @04:15PM
(#44278526)
This can be done using click.
Re:Python argparse has a limitation on argument groups that ...
by ErikBjare on Saturday June 14, 2025 @04:37PM
(#44278663)
Not with multiple=True, since it then always returns an empty list and never None, even if the default is None.
Re:Python argparse has a limitation on argument groups that ...
by dodslaser on Tuesday June 17, 2025 @06:52AM
(#44297622)
Yes it can. click.Context provides a get_parameter_source method that should help with that.
Re:Python argparse has a limitation on argument groups that ...
by ErikBjare on Thursday June 19, 2025 @04:10PM
(#44322117)
[delayed]
Re:Python argparse has a limitation on argument groups that ...
by Neywiny on Saturday June 14, 2025 @04:04PM
(#44278481)
I think this is doable but as an X vs Y problem. You can either not have a default and check if it's in the namespace later, or make the default value be the previously highest priority value as a run-time defined default. Do either of those work?
Re:Python argparse has a limitation on argument groups that ...
by mjevans on Saturday June 14, 2025 @04:53PM
(#44278759)
It would be nice if --help reports the (program) default as the default value for an option. A different option might dump a fully evaluated configuration. While a third might exit without doing anything.
Re:Python argparse has a limitation on argument groups that ...
by Elixir6419 on Thursday June 19, 2025 @07:13AM
(#44317522)
if you pass formatter_class=argparse.ArgumentDefaultsHelpFormatter) you will get exactly that.
shameless copy from https://stackoverflow.com/questions/12151306/argparse-way-to...
This is extremely important for configuration priority. Program defaults (generally) should be the lowest priority level. Superseded by configuration files. Superseded by command-line arguments. Finally replaced by configuration changes during runtime. Notably each is (in theory) specified in a more specific context as well as more recently.