[issue44748] argparse: a bool indicating if arg was encountered

2021-09-03 Thread wodny
wodny added the comment: I used a wrapper to default values. This gives me nice help message with ArgumentDefaultsHelpFormatter and easy way to update a config file dictionary with results from parse_args(). ```python from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter,

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I want the order of priority to fall back to the defaults, > if no value is specified in the config file. And if an argument > is passed via argv, then that value should take precedence > over what is set in the config file. from collections import

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread paul j3
paul j3 added the comment: Another way to play with the defaults is to use argparse.SUPPRESS. With such a default, the argument does not appear in the namespace, unless provided by the user. In [2]: p = argparse.ArgumentParser() ...: p.add_argument('--foo', default=argparse.SUPPRESS,

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread Thermi
Thermi added the comment: 1) True. That'd mean such functionality would not be usable by such a workaround though. 2) ANY setting has a default value. The output in the --help message has to, if any defaults at all are shown, be the same as the actual default values. Storing the default

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > then you can't show the defaults in the help message. 1) The --help option doesn't normally show defaults. 2) Why would you show defaults in help, if you're going to ignore them in favor the values in config whenever they aren't specified. If ignored

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread Thermi
Thermi added the comment: Raymond, then you can't show the defaults in the help message. -- ___ Python tracker ___ ___

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > With a config file loaded as part of the program, > overwrite the values loaded from the config file > if the argument was encountered in the argument vector. It seems to me that default values can already be used for this purpose: from argparse

[issue44748] argparse: a bool indicating if arg was encountered

2021-09-02 Thread wodny
Change by wodny : -- nosy: +wodny85 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue44748] argparse: a bool indicating if arg was encountered

2021-07-30 Thread Terry J. Reedy
Terry J. Reedy added the comment: Joker, please don't mess with headers. Enhancements only appear in future versions; argparse is a library module, not a test module. -- components: +Library (Lib) -Tests nosy: +terry.reedy stage: -> test needed versions: +Python 3.11 -Python 3.9

[issue44748] argparse: a bool indicating if arg was encountered

2021-07-28 Thread paul j3
paul j3 added the comment: More on the refactoring of error handling in _parse_known_args https://bugs.python.org/issue29670#msg288990 This is in a issue wanting better handling of the pre-populated "required" arguments, https://bugs.python.org/issue29670 argparse: does not respect

[issue44748] argparse: a bool indicating if arg was encountered

2021-07-28 Thread paul j3
paul j3 added the comment: I've explored something similar in https://bugs.python.org/issue11588 Add "necessarily inclusive" groups to argparse There is a local variable in parser._parse_known_args seen_non_default_actions that's a set of the actions that have been seen. It is used

[issue44748] argparse: a bool indicating if arg was encountered

2021-07-28 Thread paul j3
paul j3 added the comment: Joker 'type=bool' has been discussed in other issues. 'bool' is an existing python function. Only 'bool("")' returns False. Write your own 'type' function if you want to test for specific strings. It's too language-specific to add as a general purpose

[issue44748] argparse: a bool indicating if arg was encountered

2021-07-28 Thread hai shi
Change by hai shi : -- nosy: +paul.j3, rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue44748] argparse: a bool indicating if arg was encountered

2021-07-28 Thread Thermi
Thermi added the comment: joker, that is a different issue from the one described here. Please open your own. -- ___ Python tracker ___

[issue44748] argparse: a bool indicating if arg was encountered

2021-07-28 Thread Black Joker
Black Joker added the comment: I would like to use argparse to parse boolean command-line arguments written as "--foo True" or "--foo False". For example: my_program --my_boolean_flag False However, the following test code does not do what I would like: import argparse parser =

[issue44748] argparse: a bool indicating if arg was encountered

2021-07-27 Thread Thermi
New submission from Thermi : It'd be great if as part of the namespace returned by argparse.ArgumentParser.parse_args(), there was a bool indicating if a specific argument was encountered. That could then be used to implement the following behaviour: With a config file loaded as part of the