classification
Title: Default value shown by argparse.ArgumentDefaultsHelpFormatter is backwards for action='store_false'
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Colin Morris, paul.j3, r.david.murray
Priority: normal Keywords:

Created on 2016-05-29 16:39 by Colin Morris, last changed 2016-11-23 23:19 by paul.j3. This issue is now closed.

Messages (2)
msg266602 - (view) Author: Colin Morris (Colin Morris) Date: 2016-05-29 16:39
Small example:

    import argparse
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--no-foo', dest='foo', action='store_false', help="Suppress foo")
    args = parser.parse_args()
    print('foo = {}'.format(args.foo))

Output with "-h":

optional arguments:
  -h, --help  show this help message and exit
  --no-foo    Suppress foo (default: True)

A reasonable person reading that would think that we suppress foo by default. But actually, foo is True by default - "--no-foo" is off by default. I would suggest that if action='store_false', the default value reported by the formatter should be flipped.
msg266623 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-05-29 20:01
The message is correct.  The default value of foo is True.  It would be just as misleading to say default: False, since that would imply the default value of foo was false.  It also makes no sense to think it would mean the default value of 'no-foo' is False.

Instead, if you want to use ArgumentDefaultsHelpFormatter instead of controlling when defaults are displayed, change your help string to read something like: "Set foo to False".
History
Date User Action Args
2016-11-23 23:19:47paul.j3setnosy: + paul.j3
2016-05-29 20:01:47r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg266623

resolution: not a bug
stage: resolved
2016-05-29 16:39:34Colin Morriscreate