[New-bugs-announce] [issue9026] [argparse] Subcommands not printed in the same order they were added

Javier report at bugs.python.org
Fri Jun 18 12:24:39 CEST 2010


New submission from Javier <javier.collado at gmail.com>:

What steps will reproduce the problem?
1. Run 'python subcommands.py -h' (attached file)
2. Check the ordering of the subcommands in the output:
----
subcommands:
  {a,c,b,e,d}
    a          a subcommand help
    b          b subcommand help
    c          c subcommand help
    d          d subcommand help
    e          e subcommand help
----

The ordering between brackets is different than the ordering in the one-line help for each command below. This could be a little confusing to the user.


What is the expected output? What do you see instead?
The expected output would be to use the same ordering in both places. In particular the same ordering that was used in the code when using the _SubParsersAction.add_parser method:
----
subcommands:
  {a,b,c,d,e}
    a          a subcommand help
    b          b subcommand help
    c          c subcommand help
    d          d subcommand help
    e          e subcommand help
----


What version of the product are you using? On what operating system?
OS: Ubuntu
Version: source code (rev. 87)
Python: 2.6.5

Please provide any additional information below.
Please have a look at the attached diff. It contains a patch that worked for me to preserve the ordering used in the code.

To make that possible it uses action._choices_actions (a list) instead of action.choices (a dictionary).

----------
components: Library (Lib)
files: subcommands.py
messages: 108096
nosy: jcollado
priority: normal
severity: normal
status: open
title: [argparse] Subcommands not printed in the same order they were added
type: behavior
versions: Python 2.7, Python 3.2
Added file: http://bugs.python.org/file17704/subcommands.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9026>
_______________________________________


More information about the New-bugs-announce mailing list