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.

Author hhuang
Recipients hhuang, larry
Date 2015-05-20.22:35:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1432161314.48.0.939908418066.issue24251@psf.upfronthosting.co.za>
In-reply-to
Content
When I was trying to add the same argument to both the root command and the sub command and you put the arguments before the subcommand, In 2.7.8 the arguments would be parsed correctly. But in 2.7.9, they wouldn't but these arguments would show up in the help doc:(

For python2.7.8
~$ python2.7
Python 2.7.8 (default, Oct 29 2014, 13:45:48)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>>
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument("-s", dest="start")
_StoreAction(option_strings=['-s'], dest='start', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>>
>>> subparsers = parser.add_subparsers()
>>> subparser = subparsers.add_parser("command")
>>> subparser.add_argument("-s", dest="start")
_StoreAction(option_strings=['-s'], dest='start', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>>
>>> parser.parse_args(["-s", "1", "command"])
Namespace(start='1')
>>> parser.parse_args(["command", "-s", "1"])
Namespace(start='1')

For python 2.7.9
~$ python2.7
Python 2.7.9 (default, Apr 2 2015, 15:33:21)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument("-s", dest="start")
_StoreAction(option_strings=['-s'], dest='start', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>>
>>> subparsers = parser.add_subparsers()
>>> subparser = subparsers.add_parser("command")
>>> subparser.add_argument("-s", dest="start")
_StoreAction(option_strings=['-s'], dest='start', nargs=None, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>>
>>> parser.parse_args(["-s", "1", "command"])
Namespace(start=None)
>>> parser.parse_args(["command", "-s", "1"])
Namespace(start='1')
History
Date User Action Args
2015-05-20 22:35:14hhuangsetrecipients: + hhuang, larry
2015-05-20 22:35:14hhuangsetmessageid: <1432161314.48.0.939908418066.issue24251@psf.upfronthosting.co.za>
2015-05-20 22:35:14hhuanglinkissue24251 messages
2015-05-20 22:35:14hhuangcreate