[Python-checkins] cpython: Fix bug with argparse.Parser.parse_args(*args)
georg.brandl
python-checkins at python.org
Sun Sep 9 11:19:18 CEST 2012
http://hg.python.org/cpython/rev/8c2e87aeb707
changeset: 78910:8c2e87aeb707
user: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
date: Sun Sep 02 14:59:19 2012 +0200
summary:
Fix bug with argparse.Parser.parse_args(*args)
files:
Lib/argparse.py | 5 ++++-
Lib/test/test_argparse.py | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/Lib/argparse.py b/Lib/argparse.py
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1709,9 +1709,12 @@
return args
def parse_known_args(self, args=None, namespace=None):
- # args default to the system args
if args is None:
+ # args default to the system args
args = _sys.argv[1:]
+ else:
+ # make sure that args are mutable
+ args = list(args)
# default Namespace built from parser defaults
if namespace is None:
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -4565,6 +4565,24 @@
class TestParseKnownArgs(TestCase):
+ def test_arguments_tuple(self):
+ parser = argparse.ArgumentParser()
+ parser.parse_args(())
+
+ def test_arguments_list(self):
+ parser = argparse.ArgumentParser()
+ parser.parse_args([])
+
+ def test_arguments_tuple_positional(self):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('x')
+ parser.parse_args(('x',))
+
+ def test_arguments_list_positional(self):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('x')
+ parser.parse_args(['x'])
+
def test_optionals(self):
parser = argparse.ArgumentParser()
parser.add_argument('--foo')
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list