paul j3 <ajipa...@gmail.com> added the comment:

Parsing is a two step process.  First the strings are passed through

def _parse_optional(self, arg_string):

which classifies them as 'O', an optional flag, or 'A', an argument.

- no prefix char => A
- the string is in the dictionary of option_strings (e.g. '--list-arg') => O
- one char => A
- has '=' and first part in option_strings => O
- test for abreviations
- negative number => O or A
- contains space => A
- else => unmatched O?

(read it for the details)

With your inputs, the pattern is:

['--list-arg', 'a', '--text-arg', 'hello world']
O A O? A

['--list-arg', 'a', '--text-arg=hello']
O A O?

['--list-arg', 'a', '--text-arg=hello world']
O A A

It's the space in the string marks it as an argument that can be added to the 
'--list-arg' list.

Unmatched optionals go on the 'extras' list.

---

In [25]: parser.parse_known_args(['--list-arg', 'a', '--text-arg', 'hello 
world'])
Out[25]: (Namespace(list_arg=['a']), ['--text-arg', 'hello world'])

In [26]: parser.parse_known_args(['--list-arg', 'a', '--text-arg=hello'])
Out[26]: (Namespace(list_arg=['a']), ['--text-arg=hello'])

In [32]: parser.parse_known_args(['--list-arg', 'a', '--text-arg=hello world'])
Out[32]: (Namespace(list_arg=['a', '--text-arg=hello world']), [])

---

So '--text-arg=hello world' is split into ['--text-arg', 'hello world'] only if 
'--text-arg' is an option_string.

Any ways, the behavior is explainable.  Whether the blank should have this 
priority might be debatable, but I suspect any changes will be rejected on the 
grounds of backward incompatibility.  

Your users still have the option of using:

--text-arg 'hello world'

It may be worth search the issues for an earlier discussion.

----------
nosy: +paul.j3

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34390>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to