This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2014年12月15日 21:02 by remram, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Messages (6) | |||
|---|---|---|---|
| msg232679 - (view) | Author: Rémi Rampin (remram) * | Date: 2014年12月15日 21:02 | |
This works correctly on Python 3.4.
On Python 2.7, argparse seems to completely and silently ignore arguments in some conditions, for instance this setup will cause --verbose to be ignored on the main parser:
options = argparse.ArgumentParser(add_help=False)
options.add_argument('-v', '--verbose', action='store_true')
parser = argparse.ArgumentParser(parents=[options])
subparsers = parser.add_subparsers()
parser_cmd = subparsers.add_parser('cmd', parents=[options])
Full runnable example here: http://paste.pound-python.org/show/XfVVhdJHSPISXLP1lASd/
Might or might not be related to #9351, workarounds welcome.
|
|||
| msg232682 - (view) | Author: Rémi Rampin (remram) * | Date: 2014年12月15日 21:20 | |
Interestingly, this worked before my upgrade 2.7.8 -> 2.7.9. |
|||
| msg233040 - (view) | Author: (Changaco) | Date: 2014年12月23日 10:48 | |
honcho has been affected by this: https://github.com/nickstenning/honcho/issues/122 Working around the problem is possible but not very pretty: https://github.com/nickstenning/honcho/pull/121 |
|||
| msg233314 - (view) | Author: Rémi Rampin (remram) * | Date: 2015年01月02日 16:12 | |
I might use your workaround in ReproZip (https://github.com/ViDA-NYU/reprozip/issues/89), thanks. I agree that it doesn't look pretty... |
|||
| msg239433 - (view) | Author: paul j3 (paul.j3) * (Python triager) | Date: 2015年03月27日 20:36 | |
Without actually running this case I think it is caused by the http://bugs.python.org/issue9351 patch. You can check the __call__ method for class _SubParsersAction and how it handles invocation of the subparser. Does it get the existing namespace, or a new one (None)? There is an inherent ambiguity when the same argument ('dest' actually) is defined for both the parser and the subparser. Doubly so when both get it via 'parents'. Which default and which argument string has priority? That other issue tried to fix the case where the subparser's default was being ignored, and in the process created a case where the parser's argument string is being ignored. Wouldn't it be safer all around if the subparsers took different arguments, or at least different namespace 'dest', than the main parser? |
|||
| msg242201 - (view) | Author: Barry A. Warsaw (barry) * (Python committer) | Date: 2015年04月28日 18:53 | |
> Wouldn't it be safer all around if the subparsers took different arguments, or at least different namespace 'dest', than the main parser? IMHO, yes. I agree that the semantics of what the original code is trying to do is quite ambiguous. Since the documentation says that parents= causes all the given parsers and adds their options to the parser being constructed, I'd take that to mean that the -v before the command, and the command's -v would point to the same dest. The admonition for add_help=False seems to reinforce that. The fact that this used to work should be considered an accident. I wouldn't call it a regression because the documentation does not make it clear that this should work. I think this is not a bug. Feel free to reopen this if you disagree and and cite a convincing argument for sharing dests. To be totally unambiguous, use different destinations. FWIW, I've never used parents myself. I've always done something like what honcho eventually landed. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:11 | admin | set | github: 67247 |
| 2015年04月28日 18:53:13 | barry | set | status: open -> closed resolution: not a bug messages: + msg242201 |
| 2015年04月28日 18:39:26 | barry | set | nosy:
+ barry |
| 2015年03月31日 18:28:59 | berker.peksag | link | issue23555 superseder |
| 2015年03月27日 20:36:04 | paul.j3 | set | messages: + msg239433 |
| 2015年03月27日 20:18:29 | paul.j3 | set | nosy:
+ paul.j3 |
| 2015年03月23日 23:15:26 | gregory.p.smith | set | nosy:
+ r.david.murray, nailor versions: + Python 3.4, Python 3.5 |
| 2015年03月23日 22:04:30 | gregory.p.smith | set | nosy:
+ gregory.p.smith |
| 2015年01月02日 16:12:43 | remram | set | messages: + msg233314 |
| 2014年12月23日 10:48:50 | Changaco | set | nosy:
+ Changaco messages: + msg233040 |
| 2014年12月15日 21:20:51 | remram | set | messages: + msg232682 |
| 2014年12月15日 21:02:07 | remram | create | |