zenlotus / argparse

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

Bug when parsing long optionals with spaces in the value #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Run this script against the head of svn:

  import argparse
  parser = argparse.ArgumentParser()
  parser.add_argument('--foo')
  print parser.parse_args(['--foo=bar baz'])

What is the expected output? What do you see instead?
Expected output:
Namespace(foo='bar baz')

Actual output:
usage: test.py [-h] [--foo FOO]
test.py: error: unrecognized arguments: --foo=bar baz

What version of the product are you using? On what operating system?
This happens on the head of svn.  Not sure when it was introduced.

Please provide any additional information below.
I've attached a patch that I think fixes it.  Thanks.

Original issue reported on code.google.com by zhir...@gmail.com on 17 Jul 2009 at 8:28

Attachments:

GoogleCodeExporter commented 9 years ago
Seems like there's some disagreement on what is the right behavior here. Take a 
look
at issue10, which suggests that the following should be parsed as a positional 
an
optional and a positional:

  foo --bar '-r is an option string'

I don't have a good intuition for which one makes more sense. Note that you can 
work
around your issue with something like:

  parser.parse_args(['--foo', 'bar baz'])

Original comment by steven.b...@gmail.com on 21 Jul 2009 at 2:57

GoogleCodeExporter commented 9 years ago
I looked at this a little longer, and I think your patch is okay. Before, if an
argument contained a space, it was always a positional. Now, if it contains a 
space,
it's a positional only if it doesn't start with an optional declared in the 
parser.
That's a little harder to explain, but probably more useful behavior.

I committed your patch in r35.

Original comment by steven.b...@gmail.com on 26 Jul 2009 at 3:17