[New-bugs-announce] [issue41769] Positional arguments which use store boolean actions do not behave as other actions.

Rafael Guterres Jeffman report at bugs.python.org
Fri Sep 11 22:38:08 EDT 2020


New submission from Rafael Guterres Jeffman <rjeffman at redhat.com>:

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.

----------
components: Library (Lib)
messages: 376764
nosy: rjeffman
priority: normal
severity: normal
status: open
title: Positional arguments which use store boolean actions do not behave as other actions.
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41769>
_______________________________________


More information about the New-bugs-announce mailing list