[New-bugs-announce] [issue24338] In argparse adding wrong arguments makes malformed namespace

py.user report at bugs.python.org
Sun May 31 13:01:36 CEST 2015


New submission from py.user:

>>> import argparse
>>> 
>>> parser = argparse.ArgumentParser()
>>> _ = parser.add_argument('foo bar')
>>> _ = parser.add_argument('--x --y')
>>> args = parser.parse_args(['abc'])
>>> 
>>> args
Namespace(foo bar='abc', x __y=None)
>>> 
>>> 'foo bar' in dir(args)
True
>>> 'x __y' in dir(args)
True
>>>

Passing wrong arguments silently makes a namespace which attributes are not accessible.

ISTM, add_argument() should raise a ValueError exception.

----------
components: Library (Lib)
messages: 244534
nosy: py.user
priority: normal
severity: normal
status: open
title: In argparse adding wrong arguments makes malformed namespace
type: behavior
versions: Python 3.4, Python 3.5

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


More information about the New-bugs-announce mailing list