Steven Bethard <steven.beth...@gmail.com> added the comment:

I'm sympathetic to the idea that '-' should be translated similarly for 
optional and positional arguments, but as you've noted, it would be a risky 
patch because it's already possible for people to use getattr on hyphenated 
arguments. So I think this isn't possible without a long deprecation process 
first.

> But patching the module to allow explicitly setting dest via keyword 
> argument shouldn't hurt anybody.

I agree that it wouldn't hurt anybody. If you can find a way to do this, feel 
free to provide a patch.

However, the correct way to have one name for the attribute (i.e. dest=) and 
one name for the help (i.e. metavar=) is to use the metavar argument like so:

    parser.add_argument('positional_args', metavar='positional-args')

That said, this is not the first time I've seen someone run into this problem. 
I think the documentation could be improved in a few ways:

(1) In the "name or flags" section, describe how the flags (for optional 
arguments) are translated into both a default "dest" (stripping initial '-' and 
converting '-' to '_') and into a default "metavar" (stripping initial '-' and 
uppercasing). Part of this is in the "dest" and "metavar" documentation, but 
probably belongs up in the "name or flags" documentation. Add cross-references 
to "dest" and "metavar" sections.

(2) In the "name or flags" section, describe how the name (for positional 
arguments) are translated into the same default "dest" and "metavar" (no string 
munging at all). Again, move stuff from the "dest" and "metavar" sections as 
necessary. Add cross-references to "dest" and "metavar" sections.

(3) In the "dest" section and somewhere in the "parse_args" section, describe 
how "getattr" can be used to get attributes whose names aren't valid Python 
identifiers. Maybe cross-reference this section from the edits in (2).

----------
assignee:  -> docs@python
components: +Documentation
nosy: +docs@python
versions: +Python 3.4

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

Reply via email to