[issue15929] argparse non alphanum characters replacement

2012-09-12 Thread Julien Castets

New submission from Julien Castets:

argparse.add_argument replaces dashes with underscores. If an argument contains 
another non alphanum character, accessing to it will result to a syntax error.

#! /usr/bin/env python

import argparse

if __name__ == '__main__':
argParser = argparse.ArgumentParser()
argParser.add_argument('--foo+', action='store_true')
arguments = argParser.parse_args()

print 'getattr foo+: %s' % getattr(arguments, 'foo+') # ok
print arguments.foo+ # syntax error

The patch replaces every non alnum character with an underscore.

--
components: None
files: argparse.patch
keywords: patch
messages: 170361
nosy: brmzkw
priority: normal
severity: normal
status: open
title: argparse non alphanum characters replacement
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file27178/argparse.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15929
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15929] argparse non alphanum characters replacement

2012-09-12 Thread R. David Murray

R. David Murray added the comment:

It would probably be better to have the namespace object support subscripting 
in order to satisfy this use case.  You can use getattr to do it now.  (Note 
that the namespace object should probably use a real dict and a __getattr__ 
method, since I don't think the language guarantees that you can put 
non-identifiers in an attribute dict).

--
nosy: +bethard, r.david.murray
type: behavior - enhancement
versions:  -Python 2.7, Python 3.1, Python 3.2, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15929
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15929] argparse non alphanum characters replacement

2012-09-12 Thread Steven Bethard

Steven Bethard added the comment:

If you need to get things that aren't valid Python identifiers, use vars() to 
get the dictionary:

http://docs.python.org/dev/library/argparse.html#the-namespace-object

Changing all non-alphanumeric characters to underscores would be a backwards 
incompatible change for argparse (it would break existing code). That means 
we'd need to have a long deprecation period before the change. I'm not sure 
it's really worth it for this feature when vars() already gives you what you 
need easily.

I'm therefore closing this a won't fix, but if you feel really strongly that 
vars() doesn't solve your problem and you want to push through the long 
deprecation process, feel free to re-open.

@R. David Murray: I wouldn't worry about non-identifiers in an attribute dict. 
This has worked for ages, and changing this would be a seriously backwards 
incompatible change that couldn't be possible before Python 4.

--
resolution:  - wont fix
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15929
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15929] argparse non alphanum characters replacement

2012-09-12 Thread R. David Murray

R. David Murray added the comment:

Oh, it wasn't CPython that that comment was directed at.  But I think you are 
right: because CPython supports it, I think other implementations will as well, 
whatever the language spec says or doesn't say (I didn't double check, I'm 
going on a fuzzy memory of a conversation on python-dev from the pypy folks).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15929
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15929] argparse non alphanum characters replacement

2012-09-12 Thread Steven Bethard

Steven Bethard added the comment:

I haven't been following python-dev recently, but the only discussion I 
remember was for non-strings in __dict__, not non-identifiers.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15929
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com