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.

classification
Title: argparse action not correctly describing the right behavior
Type: behavior Stage: resolved
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Diego Costantini, docs@python, eric.smith
Priority: normal Keywords:

Created on 2017-04-21 13:20 by Diego Costantini, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg292044 - (view) Author: Diego Costantini (Diego Costantini) Date: 2017-04-21 13:20
Here https://docs.python.org/2/library/argparse.html#action we have the following:

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', action='store_true')
>>> parser.add_argument('--bar', action='store_false')
>>> parser.add_argument('--baz', action='store_false')
>>> parser.parse_args('--foo --bar'.split())
Namespace(bar=False, baz=True, foo=True)

baz should be False because omitted.
I also tested it.
msg292045 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-04-21 13:28
I think the example is correct. Because baz's action is store_false, the default is True. So if baz is omitted, it should have a True value. That's what the example shows, and what I see when I run this code.

Can you show what you tested, what you saw, and what you expected?
msg292046 - (view) Author: Diego Costantini (Diego Costantini) Date: 2017-04-21 13:44
You are right, I misunderstood the part where it sets defaults opposite to the stored value, although apparently over one year ago I did understand it correctly when I first went through that documentation.

Today my second pair of eyes had my same understanding of it though :)
History
Date User Action Args
2022-04-11 14:58:45adminsetgithub: 74313
2017-04-21 13:44:59Diego Costantinisetstatus: open -> closed
resolution: not a bug
messages: + msg292046

stage: resolved
2017-04-21 13:28:01eric.smithsetnosy: + eric.smith
messages: + msg292045
2017-04-21 13:20:52Diego Costantinicreate