4 ms·
Is there a standard python library that does annotate if an argument is user provided or instead (just) the default value? This is extremely important for conf
by mjevans 1y ago
Is there a standard python library that does annotate if an argument is user provided or instead (just) the default value?
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.
- Neywiny 1y agoI 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?
- mjevans 1y agoIt 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.
- Elixir6419 1y agoif you pass formatter_class=argparse.ArgumentDefaultsHelpFormatter) you will get exactly that. shameless copy from https://stackoverflow.com/questions/12151306/argparse-way-to-include-default-values-in-help https://stackoverflow.com/questions/12151306/argparse-way-to...
- dodslaser 1y agoThis can be done using click.
- ErikBjare 1y agoNot with multiple=True, since it then always returns an empty list and never None, even if the default is None.
- dodslaser 1y agoYes it can. click.Context provides a get_parameter_source method that should help with that.
- ErikBjare 1y agoThank you! I recently got bitten by this limitation and will make use of get_parameter_source. I gave you credit/mentioned in the issue to restore our use of `multiple=True` behavior: https://github.com/gptme/gptme/issues/560 https://github.com/gptme/gptme/issues/560
- deleted 1y ago[deleted]
- deleted 1y ago[deleted]