[issue26394] Have argparse provide ability to require a fallback value be present

2020-11-04 Thread Brett Cannon
Change by Brett Cannon : -- nosy: -brett.cannon ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue26394] Have argparse provide ability to require a fallback value be present

2017-05-28 Thread paul j3
paul j3 added the comment: http://bugs.python.org/issue29670 argparse: does not respect required args pre-populated into namespace wants to put 'required' values in the Namespace. That's a similar issue. An idea that I tried for that (but didn't submit as a patch) is to move the tests at the

[issue26394] Have argparse provide ability to require a fallback value be present

2016-03-11 Thread Michael Herold
Michael Herold added the comment: Yes, a fallback hook at the end of parsing would have to be placed before the 'required' testing, not after as in my 'group' testing. Just to clarify: Would you suggest that a fallback call returns the parsed value (i.e. the fallback calls the action or alike)

[issue26394] Have argparse provide ability to require a fallback value be present

2016-03-11 Thread paul j3
paul j3 added the comment: Yes, the use of ordered dictionary would be right. Your code would still reorder actions that have fallback values, but that wouldn't affect others. Yes, a fallback hook at the end of parsing would have to be placed before the 'required' testing, not after as in my

[issue26394] Have argparse provide ability to require a fallback value be present

2016-03-11 Thread Michael Herold
Michael Herold added the comment: Thanks so much for looking into my patch! Let me start by outlining that I don't understand how your alternate solutions are coping with the key problem. You are assuming that you get a populated Namespace object. However, `_parse_known_args` is exiting if

[issue26394] Have argparse provide ability to require a fallback value be present

2016-03-10 Thread paul j3
paul j3 added the comment: http://stackoverflow.com/a/35144270/901925 dynamically-set-default-value-from-cfg-file-through-argparse-python is my answer to a similar recent (Feb 2015) SO question. I rather like the idea of using collections.ChainMap on the dictionary versions of the namespace

[issue26394] Have argparse provide ability to require a fallback value be present

2016-03-10 Thread paul j3
paul j3 added the comment: Let's see if I understand the proposed patch Each call to 'take_action' is replaced with a save to a 'action_with_values' dictionary For a flagged (optional) it saves the 'args' and 'option_string'; for positionals it save 'args': -

[issue26394] Have argparse provide ability to require a fallback value be present

2016-03-10 Thread paul j3
paul j3 added the comment: I need to study that patch more, but I don't like the fact that it operates at the core of the parsing (e.g. in 'take_action'). That's a dangerous place to add features. Unexpected behaviors and backwards compatibility problems are too likely. It would be better

[issue26394] Have argparse provide ability to require a fallback value be present

2016-03-10 Thread paul j3
Changes by paul j3 : -- nosy: +paul.j3 ___ Python tracker ___ ___ Python-bugs-list

[issue26394] Have argparse provide ability to require a fallback value be present

2016-03-02 Thread Michael Herold
Changes by Michael Herold : Added file: http://bugs.python.org/file42062/example.py ___ Python tracker ___

[issue26394] Have argparse provide ability to require a fallback value be present

2016-03-02 Thread Michael Herold
Michael Herold added the comment: I have prepared a working patch to sketch how this could be implemented. A small example (example.py) shows how this feature can be used to implement a fallback to environment variables. This patch allows Currying of positional arguments (i.e. you can give

[issue26394] Have argparse provide ability to require a fallback value be present

2016-02-27 Thread Terry J. Reedy
Changes by Terry J. Reedy : -- nosy: +bethard ___ Python tracker ___ ___ Python-bugs-list

[issue26394] Have argparse provide ability to require a fallback value be present

2016-02-21 Thread Michael Herold
Michael Herold added the comment: Thank you for clarifying my request. Callables sound like a great solution to me! Looks like the fallback should be called in `take_action()` if argument_values is "empty" (None?). Per default it should be transparent to an `Action` if the values are based

[issue26394] Have argparse provide ability to require a fallback value be present

2016-02-20 Thread Brett Cannon
Changes by Brett Cannon : -- title: argparse: Add set_values() function to complement set_defaults() -> Have argparse provide ability to require a fallback value be present ___ Python tracker