Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
00528e8f
Commit
00528e8f
authored
Jul 21, 2012
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#13922: argparse no longer incorrectly strips '--' after the first one.
Patch by Jeff Knupp.
parent
b94082a7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
14 deletions
+35
-14
Lib/argparse.py
Lib/argparse.py
+5
-2
Lib/test/test_argparse.py
Lib/test/test_argparse.py
+26
-12
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/argparse.py
View file @
00528e8f
...
@@ -2186,9 +2186,12 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
...
@@ -2186,9 +2186,12 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# Value conversion methods
# Value conversion methods
# ========================
# ========================
def
_get_values
(
self
,
action
,
arg_strings
):
def
_get_values
(
self
,
action
,
arg_strings
):
# for everything but PARSER
args, strip ou
t '--'
# for everything but PARSER
, REMAINDER args, strip out firs
t '--'
if
action
.
nargs
not
in
[
PARSER
,
REMAINDER
]:
if
action
.
nargs
not
in
[
PARSER
,
REMAINDER
]:
arg_strings
=
[
s
for
s
in
arg_strings
if
s
!=
'--'
]
try
:
arg_strings
.
remove
(
'--'
)
except
ValueError
:
pass
# optional argument produces a default when not present
# optional argument produces a default when not present
if
not
arg_strings
and
action
.
nargs
==
OPTIONAL
:
if
not
arg_strings
and
action
.
nargs
==
OPTIONAL
:
...
...
Lib/test/test_argparse.py
View file @
00528e8f
...
@@ -1761,6 +1761,14 @@ class TestAddSubparsers(TestCase):
...
@@ -1761,6 +1761,14 @@ class TestAddSubparsers(TestCase):
parser2
.
add_argument
(
'-y'
,
choices
=
'123'
,
help
=
'y help'
)
parser2
.
add_argument
(
'-y'
,
choices
=
'123'
,
help
=
'y help'
)
parser2
.
add_argument
(
'z'
,
type
=
complex
,
nargs
=
'*'
,
help
=
'z help'
)
parser2
.
add_argument
(
'z'
,
type
=
complex
,
nargs
=
'*'
,
help
=
'z help'
)
# add third sub-parser
parser3_kwargs
=
dict
(
description
=
'3 description'
)
if
subparser_help
:
parser3_kwargs
[
'help'
]
=
'3 help'
parser3
=
subparsers
.
add_parser
(
'3'
,
**
parser3_kwargs
)
parser3
.
add_argument
(
't'
,
type
=
int
,
help
=
't help'
)
parser3
.
add_argument
(
'u'
,
nargs
=
'...'
,
help
=
'u help'
)
# return the main parser
# return the main parser
return
parser
return
parser
...
@@ -1790,6 +1798,10 @@ class TestAddSubparsers(TestCase):
...
@@ -1790,6 +1798,10 @@ class TestAddSubparsers(TestCase):
self
.
parser
.
parse_args
(
'--foo 0.125 1 c'
.
split
()),
self
.
parser
.
parse_args
(
'--foo 0.125 1 c'
.
split
()),
NS
(
foo
=
True
,
bar
=
0.125
,
w
=
None
,
x
=
'c'
),
NS
(
foo
=
True
,
bar
=
0.125
,
w
=
None
,
x
=
'c'
),
)
)
self
.
assertEqual
(
self
.
parser
.
parse_args
(
'-1.5 3 11 -- a --foo 7 -- b'
.
split
()),
NS
(
foo
=
False
,
bar
=-
1.5
,
t
=
11
,
u
=
[
'a'
,
'--foo'
,
'7'
,
'--'
,
'b'
]),
)
def
test_parse_known_args
(
self
):
def
test_parse_known_args
(
self
):
self
.
assertEqual
(
self
.
assertEqual
(
...
@@ -1824,15 +1836,15 @@ class TestAddSubparsers(TestCase):
...
@@ -1824,15 +1836,15 @@ class TestAddSubparsers(TestCase):
def
test_help
(
self
):
def
test_help
(
self
):
self
.
assertEqual
(
self
.
parser
.
format_usage
(),
self
.
assertEqual
(
self
.
parser
.
format_usage
(),
'usage: PROG [-h] [--foo] bar {1,2} ...
\
n
'
)
'usage: PROG [-h] [--foo] bar {1,2
,3
} ...
\
n
'
)
self
.
assertEqual
(
self
.
parser
.
format_help
(),
textwrap
.
dedent
(
'''
\
self
.
assertEqual
(
self
.
parser
.
format_help
(),
textwrap
.
dedent
(
'''
\
usage: PROG [-h] [--foo] bar {1,2} ...
usage: PROG [-h] [--foo] bar {1,2
,3
} ...
main description
main description
positional arguments:
positional arguments:
bar bar help
bar bar help
{1,2
}
command help
{1,2
,3}
command help
optional arguments:
optional arguments:
-h, --help show this help message and exit
-h, --help show this help message and exit
...
@@ -1843,15 +1855,15 @@ class TestAddSubparsers(TestCase):
...
@@ -1843,15 +1855,15 @@ class TestAddSubparsers(TestCase):
# Make sure - is still used for help if it is a non-first prefix char
# Make sure - is still used for help if it is a non-first prefix char
parser
=
self
.
_get_parser
(
prefix_chars
=
'+:-'
)
parser
=
self
.
_get_parser
(
prefix_chars
=
'+:-'
)
self
.
assertEqual
(
parser
.
format_usage
(),
self
.
assertEqual
(
parser
.
format_usage
(),
'usage: PROG [-h] [++foo] bar {1,2} ...
\
n
'
)
'usage: PROG [-h] [++foo] bar {1,2
,3
} ...
\
n
'
)
self
.
assertEqual
(
parser
.
format_help
(),
textwrap
.
dedent
(
'''
\
self
.
assertEqual
(
parser
.
format_help
(),
textwrap
.
dedent
(
'''
\
usage: PROG [-h] [++foo] bar {1,2} ...
usage: PROG [-h] [++foo] bar {1,2
,3
} ...
main description
main description
positional arguments:
positional arguments:
bar bar help
bar bar help
{1,2
}
command help
{1,2
,3}
command help
optional arguments:
optional arguments:
-h, --help show this help message and exit
-h, --help show this help message and exit
...
@@ -1862,15 +1874,15 @@ class TestAddSubparsers(TestCase):
...
@@ -1862,15 +1874,15 @@ class TestAddSubparsers(TestCase):
def
test_help_alternate_prefix_chars
(
self
):
def
test_help_alternate_prefix_chars
(
self
):
parser
=
self
.
_get_parser
(
prefix_chars
=
'+:/'
)
parser
=
self
.
_get_parser
(
prefix_chars
=
'+:/'
)
self
.
assertEqual
(
parser
.
format_usage
(),
self
.
assertEqual
(
parser
.
format_usage
(),
'usage: PROG [+h] [++foo] bar {1,2} ...
\
n
'
)
'usage: PROG [+h] [++foo] bar {1,2
,3
} ...
\
n
'
)
self
.
assertEqual
(
parser
.
format_help
(),
textwrap
.
dedent
(
'''
\
self
.
assertEqual
(
parser
.
format_help
(),
textwrap
.
dedent
(
'''
\
usage: PROG [+h] [++foo] bar {1,2} ...
usage: PROG [+h] [++foo] bar {1,2
,3
} ...
main description
main description
positional arguments:
positional arguments:
bar bar help
bar bar help
{1,2
}
command help
{1,2
,3}
command help
optional arguments:
optional arguments:
+h, ++help show this help message and exit
+h, ++help show this help message and exit
...
@@ -1879,18 +1891,19 @@ class TestAddSubparsers(TestCase):
...
@@ -1879,18 +1891,19 @@ class TestAddSubparsers(TestCase):
def
test_parser_command_help
(
self
):
def
test_parser_command_help
(
self
):
self
.
assertEqual
(
self
.
command_help_parser
.
format_usage
(),
self
.
assertEqual
(
self
.
command_help_parser
.
format_usage
(),
'usage: PROG [-h] [--foo] bar {1,2} ...
\
n
'
)
'usage: PROG [-h] [--foo] bar {1,2
,3
} ...
\
n
'
)
self
.
assertEqual
(
self
.
command_help_parser
.
format_help
(),
self
.
assertEqual
(
self
.
command_help_parser
.
format_help
(),
textwrap
.
dedent
(
'''
\
textwrap
.
dedent
(
'''
\
usage: PROG [-h] [--foo] bar {1,2} ...
usage: PROG [-h] [--foo] bar {1,2
,3
} ...
main description
main description
positional arguments:
positional arguments:
bar bar help
bar bar help
{1,2
}
command help
{1,2
,3}
command help
1 1 help
1 1 help
2 2 help
2 2 help
3 3 help
optional arguments:
optional arguments:
-h, --help show this help message and exit
-h, --help show this help message and exit
...
@@ -2001,6 +2014,7 @@ class TestAddSubparsers(TestCase):
...
@@ -2001,6 +2014,7 @@ class TestAddSubparsers(TestCase):
1 (1alias1, 1alias2)
1 (1alias1, 1alias2)
1 help
1 help
2 2 help
2 2 help
3 3 help
"""
))
"""
))
# ============
# ============
...
...
Misc/ACKS
View file @
00528e8f
...
@@ -511,6 +511,7 @@ Thomas Kluyver
...
@@ -511,6 +511,7 @@ Thomas Kluyver
Kim Knapp
Kim Knapp
Lenny Kneler
Lenny Kneler
Pat Knight
Pat Knight
Jeff Knupp
Greg Kochanski
Greg Kochanski
Damon Kohler
Damon Kohler
Marko Kohtala
Marko Kohtala
...
...
Misc/NEWS
View file @
00528e8f
...
@@ -98,6 +98,9 @@ Core and Builtins
...
@@ -98,6 +98,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #13922: argparse no longer incorrectly strips '--'s that appear
after the first one.
- Issue #12353: argparse now correctly handles null argument values.
- Issue #12353: argparse now correctly handles null argument values.
- Issues #10017 and #14998: Fix TypeError using pprint on dictionaries with
- Issues #10017 and #14998: Fix TypeError using pprint on dictionaries with
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment