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.

Author rjeffman
Recipients rjeffman
Date 2020-09-12.02:38:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1599878288.06.0.921718987462.issue41769@roundup.psfhosted.org>
In-reply-to
Content
argparse allow the use of `store_true` and `store_false` for positional arguments, and although it is weird, it should be fine, but using either action raises a behavior I believe is wrong.

Given the following Python code:

```
import argparse

arg = argparse.ArgumentParser()
arg.add_argument("opt", action="store_false")

arg.parse_args(["-h"])
```

The output is:

```
usage: t.py [-h]

positional arguments:
  opt

optional arguments:
  -h, --help  show this help message and exit
```

Note that the positional argument is not shown in the `usage` line.

When any string parameter is given, the result is:

```
usage: t.py [-h]
t.py: error: unrecognized arguments:
```

(add to the end of the output the value of the argument.)

Even if the use of a positional value is not the best way to describe boolean parameter (optional arguments provide a much better interface for such values), if argparse is to support positional boolean values they should work as other positional arguments.

I'd suggest raising an error if store_true or store_false is used along with positional values.
History
Date User Action Args
2020-09-12 02:38:08rjeffmansetrecipients: + rjeffman
2020-09-12 02:38:08rjeffmansetmessageid: <1599878288.06.0.921718987462.issue41769@roundup.psfhosted.org>
2020-09-12 02:38:08rjeffmanlinkissue41769 messages
2020-09-12 02:38:07rjeffmancreate