New submission from Rafael Guterres Jeffman :
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
<https://bugs.python.org/issue41769>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com