[issue16399] argparse: append action with default list adds to list instead of overriding

2020-11-06 Thread Irit Katriel
Change by Irit Katriel : -- versions: +Python 3.10, Python 3.8, Python 3.9 -Python 2.7, Python 3.2, Python 3.3, Python 3.4 ___ Python tracker ___

[issue16399] argparse: append action with default list adds to list instead of overriding

2020-01-02 Thread hai shi
hai shi added the comment: I update the doc of argparse and think this bpo could be closed when PR merged. -- nosy: +rhettinger ___ Python tracker ___

[issue16399] argparse: append action with default list adds to list instead of overriding

2020-01-02 Thread hai shi
Change by hai shi : -- nosy: +shihai1991 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue16399] argparse: append action with default list adds to list instead of overriding

2020-01-01 Thread hai shi
Change by hai shi : -- pull_requests: +17226 stage: -> patch review pull_request: https://github.com/python/cpython/pull/17793 ___ Python tracker ___

[issue16399] argparse: append action with default list adds to list instead of overriding

2019-12-25 Thread Roy Smith
Roy Smith added the comment: I just got bit by this in Python 3.5.3. I get why it does this. I also get why it's impractical to change the behavior now. But, it really isn't the obvious behavior, so it should be documented at

[issue16399] argparse: append action with default list adds to list instead of overriding

2018-07-30 Thread Evgeny
Evgeny added the comment: You don't need action='append'. For desired behavior you can pass action='store' with nargs='*'. I think it's a simplest workaround. -- nosy: +gun146 ___ Python tracker

[issue16399] argparse: append action with default list adds to list instead of overriding

2016-10-02 Thread paul j3
paul j3 added the comment: One thing that this default behavior does is allow us to append values to any object, just so long as it has the `append` method. The default does not have to be a standard list. For example, in another bug/issue someone asked for an `extend` action. I could

[issue16399] argparse: append action with default list adds to list instead of overriding

2016-10-02 Thread paul j3
paul j3 added the comment: It may help to know something about how defaults are handled - in general. `add_argument` and `set_defaults` set the `default` attribute of the Action (the object created by `add_argument` to hold all of its information). The default `default` is `None`. At the

[issue16399] argparse: append action with default list adds to list instead of overriding

2016-10-02 Thread Michał Klich
Michał Klich added the comment: The documentation for argparse still does not mention this behaviour. I decided to make a patch based no the optparse issue. Hopefully it is good enough to be merged. -- keywords: +patch nosy: +michal.klich Added file:

[issue16399] argparse: append action with default list adds to list instead of overriding

2016-04-13 Thread Gabriel Devenyi
Gabriel Devenyi added the comment: >From what I can tell a workaround for this still isn't documented. -- nosy: +Gabriel Devenyi ___ Python tracker ___

[issue16399] argparse: append action with default list adds to list instead of overriding

2014-08-06 Thread Yclept Nemo
Yclept Nemo added the comment: Well that won't work. Example: import argparse class TestAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): print(default: {}({})\tdest: {}({}).format(self.default, type(self.default), getattr(namespace,

[issue16399] argparse: append action with default list adds to list instead of overriding

2014-08-06 Thread paul j3
paul j3 added the comment: In my suggestion I used if 'current_value is default': without going into detail. The use of an 'is' test for integer values is tricky, as discussed in http://bugs.python.org/issue18943 int(42) is 42# True int(257) is 257 # False As with your

[issue16399] argparse: append action with default list adds to list instead of overriding

2014-06-19 Thread SylvainDe
SylvainDe added the comment: As this is likely not to get solved, is there a recommanded way to work around this issue ? Here's what I have done : import argparse def main(): Main function parser = argparse.ArgumentParser() parser.add_argument('--foo', action='append')

[issue16399] argparse: append action with default list adds to list instead of overriding

2014-06-19 Thread paul j3
paul j3 added the comment: It should be easy to write a subclass of Action, or append Action, that does what you want. It just needs a different `__call__` method. You just need a way of identifying an default that needs to be overwritten as opposed to appended to. def __call__(self,

[issue16399] argparse: append action with default list adds to list instead of overriding

2013-04-03 Thread paul j3
paul j3 added the comment: The test file, test_argparse.py, has a test case for this: 'class TestOptionalsActionAppendWithDefault' argument_signatures = [Sig('--baz', action='append', default=['X'])] successes = [ ('--baz a --baz b', NS(baz=['X', 'a', 'b'])), ] --

[issue16399] argparse: append action with default list adds to list instead of overriding

2012-11-03 Thread Markus Amalthea Magnuson
Changes by Markus Amalthea Magnuson markus.magnu...@gmail.com: -- title: argparse: - argparse: append action with default list adds to list instead of overriding ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16399

[issue16399] argparse: append action with default list adds to list instead of overriding

2012-11-03 Thread R. David Murray
R. David Murray added the comment: This behavior is inherited from optparse. I think it is more-or-less intentional, and in any case it is of long enough standing that I don't think we can change it. We documented it for optparse in another issue, but I don't think we made the corresponding