zenlotus / argparse

Automatically exported from code.google.com/p/argparse
Other
0 stars 0 forks source link

parse_known_args() fails when using subcommands #45

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Save the attached script, and run:

 python test.py A --foo

This generates the following output, which indicates that the unknown
'--foo' option is not being ignored:

  usage: test A [-h]
  test A: error: unrecognized arguments: --foo

Original issue reported on code.google.com by whart222 on 26 Nov 2009 at 12:28

Attachments:

GoogleCodeExporter commented 9 years ago
Yes, this is indeed an issue. The problem is that subparsers don't know whether
they're being called by parse_args() or parse_known_args().

I guess the most obvious way to fix this would be to add another argument to
Action.__call__ that indicates what method is being called. But that would 
break any
existing subclasses.

Another option would be to do some stack inspection using sys._getframe(). But 
that's
not guaranteed to work on other implementations of Python.

If you have any ideas how to fix this, patches are welcome.

Also, if you have a more specific example of what you're trying to do, maybe I 
can
give you a workaround.

Original comment by steven.b...@gmail.com on 6 Dec 2009 at 11:49

GoogleCodeExporter commented 9 years ago
Issue 56 has been merged into this issue.

Original comment by steven.b...@gmail.com on 15 Jan 2010 at 12:18

GoogleCodeExporter commented 9 years ago
Moved to http://bugs.python.org/issue9340

Original comment by steven.b...@gmail.com on 23 Jul 2010 at 12:01