[issue8538] Add FlagAction to argparse
paul j3
report at bugs.python.org
Thu Dec 27 17:34:51 EST 2018
paul j3 <ajipanca at gmail.com> added the comment:
Let me highlight something about
https://stackoverflow.com/a/15008806/169947
The original question was how to implement an Action that accepts 'True' or 'False' as an argument. Users often try `type=bool`, which doesn't work because of the normal behavior of the Python bool(astr) function. That's been the subject of several other bug/issues.
https://bugs.python.org/issue14392
https://bugs.python.org/issue26994
https://bugs.python.org/issue24754
https://bugs.python.org/issue21208
My answer in that SO question is
https://stackoverflow.com/a/19233287/901925
----
@mgilson's answer proposes a '--foo', '--no-foo' alternative. That is in line with this bug/issue.
parser.add_argument('--feature', dest='feature', action='store_true')
parser.add_argument('--no-feature', dest='feature', action='store_false')
parser.set_defaults(feature=True)
So the question here is whether mgilson's simple answer is enough, or do we need to add Eric's ConfigureAction class?
On a casual reading the patch proposed here shouldn't have backward compatibility issues, since it is an addon class, and doesn't modify existing classes. But it lacks tests and documentation.
Documentation for argparse is a tough issue. While advanced users want more features and more documented details, most of the SO questions come from beginners, who's eyes glaze over when they read the existing documentation.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue8538>
_______________________________________
More information about the Python-bugs-list
mailing list