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
a38e31b4
Commit
a38e31b4
authored
Nov 01, 2010
by
Steven Bethard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug 9352 where characters were being lost in parsing some short options
parent
7728a1b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
+31
-7
Lib/argparse.py
Lib/argparse.py
+7
-7
Lib/test/test_argparse.py
Lib/test/test_argparse.py
+24
-0
No files found.
Lib/argparse.py
View file @
a38e31b4
...
...
@@ -1794,13 +1794,13 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
chars
=
self
.
prefix_chars
if
arg_count
==
0
and
option_string
[
1
]
not
in
chars
:
action_tuples
.
append
((
action
,
[],
option_string
))
for
char
in
self
.
prefix_chars
:
option_string
=
char
+
explicit_arg
[
0
]
explicit_arg
=
explicit_arg
[
1
:]
or
None
optionals_map
=
self
.
_option_string_actions
if
option_string
in
optionals_map
:
action
=
optionals_map
[
option_string
]
break
char
=
option_string
[
0
]
option_string
=
char
+
explicit_arg
[
0
]
new_
explicit_arg
=
explicit_arg
[
1
:]
or
None
optionals_map
=
self
.
_option_string_actions
if
option_string
in
optionals_map
:
action
=
optionals_map
[
option_string
]
explicit_arg
=
new_explicit_arg
else
:
msg
=
_
(
'ignored explicit argument %r'
)
raise
ArgumentError
(
action
,
msg
%
explicit_arg
)
...
...
Lib/test/test_argparse.py
View file @
a38e31b4
...
...
@@ -465,6 +465,30 @@ class TestOptionalsAlternatePrefixCharsAddedHelp(ParserTestCase):
(
'/ba +f'
,
NS
(
f
=
True
,
bar
=
None
,
baz
=
42
))
]
class
TestOptionalsAlternatePrefixCharsMultipleShortArgs
(
ParserTestCase
):
"""Verify that Optionals must be called with their defined prefixes"""
parser_signature
=
Sig
(
prefix_chars
=
'+-'
,
add_help
=
False
)
argument_signatures
=
[
Sig
(
'-x'
,
action
=
'store_true'
),
Sig
(
'+y'
,
action
=
'store_true'
),
Sig
(
'+z'
,
action
=
'store_true'
),
]
failures
=
[
'-w'
,
'-xyz'
,
'+x'
,
'-y'
,
'+xyz'
,
]
successes
=
[
(
''
,
NS
(
x
=
False
,
y
=
False
,
z
=
False
)),
(
'-x'
,
NS
(
x
=
True
,
y
=
False
,
z
=
False
)),
(
'+y -x'
,
NS
(
x
=
True
,
y
=
True
,
z
=
False
)),
(
'+yz -x'
,
NS
(
x
=
True
,
y
=
True
,
z
=
True
)),
]
class
TestOptionalsShortLong
(
ParserTestCase
):
"""Test a combination of single- and double-dash option strings"""
...
...
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