Issue 28210: argparse with subcommands difference in python 2.7 / 3.5 (original) (raw)

Issue28210

Created on 2016-09-20 08:43 by stephan, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
test_argparse.py stephan,2016-09-20 08:43
Messages (5)
msg277017 - (view) Author: stephan (stephan) Date: 2016-09-20 08:43
In python 2.7.12 I get an error if I do not pass arguments, while in python 3.5.2 I do not get the error (it fails silently). Stumbled on this during my migration of my python 2.7 code to python 3.5 for django. Here is the console output: D:\util\python\test>py -3 test_argparse.py 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22🔞55) [MSC v.1900 64 bit (AMD64)] Use subparsers: True Namespace(command=None) D:\util\python\test>py -2 test_argparse.py 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] Use subparsers: True usage: test_argparse.py [-h] command ... test_argparse.py: error: too few arguments D:\util\python\test>
msg277028 - (view) Author: Tim Graham (Tim.Graham) * Date: 2016-09-20 13:48
The behavior change is from #10424. Do you believe the new behavior is incorrect?
msg277099 - (view) Author: stephan (stephan) Date: 2016-09-21 06:52
I am not an expert with argparse since I just started using it (and it has quite a lot of features which are not all self-explaining to me). But if I didn't misunderstand something it should behave like the python 2.7 version: If I do not pass any command I am told that I missed the parameter. Or: - are there some parameters I missed to make them behave equally? - what is the intention to fail silently?
msg277154 - (view) Author: Tim Graham (Tim.Graham) * Date: 2016-09-21 15:07
Based on the usage output, it looks like the subcommand is required, but I'm not sure if there are cases where a subcommand could be optional. David, can you advise? usage: test_argparse.py [-h] command ...
msg277566 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2016-09-27 23:47
Yes there was/is a bug that made subparsers optional. http://bugs.python.org/issue9253
History
Date User Action Args
2022-04-11 14:58:37 admin set github: 72397
2016-09-28 21:12:42 Mariatta set nosy: + Mariatta
2016-09-27 23:47:35 paul.j3 set nosy: + paul.j3messages: +
2016-09-21 15:07:57 Tim.Graham set nosy: + r.david.murraymessages: +
2016-09-21 06:52:41 stephan set messages: +
2016-09-20 13:48:37 Tim.Graham set nosy: + Tim.Grahammessages: +
2016-09-20 08:43:54 stephan create