[issue8538] Add FlagAction to argparse

2019-09-13 Thread Stéphane Wirtel

Stéphane Wirtel  added the comment:

I have merged the PR 11478 and this feature will be included into 3.9.

Thank you for your proposal of Remi and thank you to Eric for the idea of this 
feature.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2019-09-13 Thread Stéphane Wirtel

Stéphane Wirtel  added the comment:


New changeset 6a517c674907c195660fa9178a7b561de49cc721 by Stéphane Wirtel (Rémi 
Lapeyre) in branch 'master':
bpo-8538: Add support for boolean actions to argparse (GH-11478)
https://github.com/python/cpython/commit/6a517c674907c195660fa9178a7b561de49cc721


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2019-09-13 Thread Stéphane Wirtel

Stéphane Wirtel  added the comment:

I am also interested by this feature.

--
nosy: +matrixise

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2019-09-13 Thread Stéphane Wirtel

Change by Stéphane Wirtel :


--
versions: +Python 3.9 -Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2019-01-09 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

I made a first proposal for this feature in PR 11478, I had to adapt 
argparse.Action to customize how the action is represented in the usage string 
by adding a format_usage() method that would default to the current behavior if 
not overridden.

Other methods to do this may be better but I did not find them.

--
versions: +Python 3.7, Python 3.8 -Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2019-01-09 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
keywords: +patch, patch, patch
pull_requests: +10987, 10988, 10989
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2019-01-09 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
keywords: +patch, patch
pull_requests: +10987, 10988
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2019-01-09 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
keywords: +patch
pull_requests: +10987
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2019-01-05 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

> I also removed myself from the issue, I'm not interested to implement it.

I would like to try and implement the change. I will open a PR shortly.

--
nosy: +remi.lapeyre

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2019-01-04 Thread STINNER Victor


STINNER Victor  added the comment:

I reopen the issue since it seems like there are people requesting the feature. 
(I also removed myself from the issue, I'm not interested to implement it.)

--
resolution: out of date -> 
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2018-12-27 Thread Ken Williams


Ken Williams  added the comment:

Thanks, Paul and Eric, for your very quick replies.

You're quite correct, the original question in 
https://stackoverflow.com/a/15008806/169947 is indeed hoping for `--foo TRUE` 
and `--foo False` etc. to work.  Personally I don't like that as much as the 
GNU-style `--foo` and `--no-foo` technique, because when you let people type 
`TRUE` or `True` or `T` or `1`, etc., it gets a bit confusing about exactly 
what is accepted as a true value, what's false, is a zero interpreted as 0 or 
"0", whether a failure to parse the value as True or False will be reported as 
an error or not, and so on.  The user typically can't really know these answers 
without reading the actual code, or running it to see what generates an error 
(or triggers whatever behavior they're looking for), which is certainly not 
ideal.

By contrast, with `--foo` and `--no-foo`, the options are strict and clear.  
And supplying an argument will trigger a parse failure.

For @mgilson's proposal, I think the main thing I find unsatisfactory (besides 
the fact that it takes 3 lines to define, and I'll have to come back to that SO 
answer every time to make sure I get them right...) is that the `--help` output 
can't be made clear.  With the following specification:

parser.add_argument('--foo', dest='foo', help="Do foo", action='store_true')
parser.add_argument('--no-foo', dest='foo', help="Don't foo", 
action='store_false')
parser.set_defaults(foo=True)

we get the following --help text (when using ArgumentDefaultsHelpFormatter):

--foo   Do foo (default: True)
--no-fooDon't foo (default: True)

and that last line seems to be a contradiction, or at least very confusing.  
The only alternative I see is to turn off ArgumentDefaultsHelpFormatter, but I 
think the defaults are generally helpful information for the user.

To fix that --help issue seems to require quite a bit more complicated 
registration of arguments, so it's probably not going to happen in most 
people's scripts.

I should be clear: I haven't vetted the `argparse_bool.py` proposal in detail 
either, so I'm not specifically asking for it to be adopted.  Just hoping for a 
nice resolution to the `--foo` `--no-foo` issue that codifies best-practices in 
a way that makes it trivial to get nice behavior in scripts.


As for documentation - I had poked around in the code a bit and seen the 
`register` method, but I thought since it wasn't documented, I'd better not use 
it.  Is it for public consumption?  If so, I'd say it's better documented than 
undocumented, even if it provides more info than most people need.  My guess is 
that enough people are probably using it to make it impossible to eliminate, 
which is a good test for whether something should be documented too.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2018-12-27 Thread Eric V. Smith


Eric V. Smith  added the comment:

Yes, this is the correct bug tracker.

And note that this code isn't mine, I just posted it here so it wouldn't be 
lost. It looks like the original message was from 
https://mail.python.org/pipermail/python-dev/2010-April/099704.html

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2018-12-27 Thread paul j3


paul j3  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2018-12-27 Thread Yaniv Aknin


Change by Yaniv Aknin :


--
nosy:  -Yaniv.Aknin

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2018-12-27 Thread Ken Williams


Ken Williams  added the comment:

@vstinner - I don't think that conclusion is correct, here is a very 
highly-upvoted answer on SO that indicates a lot of people are still looking 
for this:

https://stackoverflow.com/a/15008806/169947

I myself asked a related (more focused?) question where I was directed here:

https://stackoverflow.com/q/53937481/169947

I'm guessing the right thing to do now would be refocus the merge request in a 
new ticket - is this still the right tracker?

--
nosy: +Ken Williams

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2016-07-12 Thread STINNER Victor

STINNER Victor added the comment:

I'm sorry but there is no activity since 4 years, so I guess that the feature 
is not common enough to require a builtin support in argparse.

--
nosy: +haypo
resolution:  -> out of date
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2016-06-20 Thread paul j3

Changes by paul j3 :


--
nosy: +paul.j3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2015-04-29 Thread Wolfgang Maier

Changes by Wolfgang Maier wolfgang.ma...@biologie.uni-freiburg.de:


--
nosy: +wolma

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8538
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2012-07-22 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

On the off chance that someone was waiting for feedback from me, I'll say:

(1) A simple boolean --foo/--no-foo action seems useful to me. I would probably 
call it BooleanOptionalAction rather than FlagAction. (Almost anything could be 
considered a flag.)

(2) At the moment, argparse doesn't supply any actions, so I don't think we 
should make a separate namespace for them. If it starts to grow a list of such 
actions, we can add a separate namespace later. (And given that the name will 
end with Action, I think it should be pretty clear without the namespace.)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8538
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2011-12-11 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


--
nosy: +berkerpeksag

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8538
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8538] Add FlagAction to argparse

2010-11-19 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

I think FlagAction should implement strictly boolean options, that is --foo and 
--no-foo, without arguments at all.

For ConfigureAction, there is a precedent (unless I’m mistaken) in configure, 
which permits such things:
  --without-unicode
  --with-unicode=ucs4
  --with-unicode (uses default value for arg)

I say we focus on the simple FlagAction for this bug and keep ConfigureAction 
for another patch.

Yaniv: Can you give us a status update?

--
keywords: +easy
title: Add ConfigureAction to argparse - Add FlagAction to argparse

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8538
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com