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.

classification
Title: argparse with subcommands difference in python 2.7 / 3.5
Type: behavior Stage:
Components: Versions: Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Mariatta, Tim.Graham, paul.j3, r.david.murray, stephan
Priority: normal Keywords:

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:18: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:37adminsetgithub: 72397
2016-09-28 21:12:42Mariattasetnosy: + Mariatta
2016-09-27 23:47:35paul.j3setnosy: + paul.j3
messages: + msg277566
2016-09-21 15:07:57Tim.Grahamsetnosy: + r.david.murray
messages: + msg277154
2016-09-21 06:52:41stephansetmessages: + msg277099
2016-09-20 13:48:37Tim.Grahamsetnosy: + Tim.Graham
messages: + msg277028
2016-09-20 08:43:54stephancreate