[issue24338] In argparse adding wrong arguments makes malformed namespace

paul j3 report at bugs.python.org
Wed Jun 3 19:13:47 CEST 2015


paul j3 added the comment:

The code that converts '-' to '_' is independent of the code that uses 'prefix_chars'.

The '-' conversion handles a long standing UNIX practice of allowing that character in the middle of option flags.  It's an attempt to turn such flags into valid variable names.  There is a bug/issue about whether the conversion should be applied to positional argument 'dest' parameters.  

Is the use of other funny characters in optional flags common enough to warrant a patch?  It probably wouldn't be hard to convert all 'prefix_chars' to '_'.  But should it still convert '-', even if it isn't in that list?  What about users who are content with using 'getattr', and don't want the conversion?

Note also that you can invoke `parse_args` with your own custom Namespace object.

https://docs.python.org/3.4/library/argparse.html#the-namespace-object

This means you can write a Namespace class alternative that can handle funny characters in any way you want.  I discuss the use of custom Namespace classes in http://bugs.python.org/issue9351.

Between the availability of 'getattr' and namespace customization, I don't think there's anything here that requires a patch.  But I'm in favor of keeping the issue open for discussion.

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

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


More information about the Python-bugs-list mailing list