Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
68f555c0
Kaydet (Commit)
68f555c0
authored
Tem 22, 2012
tarafından
R David Murray
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#13922: argparse no longer incorrectly strips '--' after the first one.
Patch by Jeff Knupp.
üst
056c31f9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
14 deletions
+34
-14
argparse.py
Lib/argparse.py
+5
-2
test_argparse.py
Lib/test/test_argparse.py
+25
-12
ACKS
Misc/ACKS
+1
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/argparse.py
Dosyayı görüntüle @
68f555c0
...
...
@@ -2174,9 +2174,12 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# Value conversion methods
# ========================
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
]:
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
if
not
arg_strings
and
action
.
nargs
==
OPTIONAL
:
...
...
Lib/test/test_argparse.py
Dosyayı görüntüle @
68f555c0
...
...
@@ -1764,6 +1764,14 @@ class TestAddSubparsers(TestCase):
parser2
.
add_argument
(
'-y'
,
choices
=
'123'
,
help
=
'y 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
parser
...
...
@@ -1793,6 +1801,10 @@ class TestAddSubparsers(TestCase):
self
.
parser
.
parse_args
(
'--foo 0.125 1 c'
.
split
()),
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
):
self
.
assertEqual
(
...
...
@@ -1827,15 +1839,15 @@ class TestAddSubparsers(TestCase):
def
test_help
(
self
):
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
(
'''
\
usage: PROG [-h] [--foo] bar {1,2} ...
usage: PROG [-h] [--foo] bar {1,2
,3
} ...
main description
positional arguments:
bar bar help
{1,2
}
command help
{1,2
,3}
command help
optional arguments:
-h, --help show this help message and exit
...
...
@@ -1846,15 +1858,15 @@ class TestAddSubparsers(TestCase):
# Make sure - is still used for help if it is a non-first prefix char
parser
=
self
.
_get_parser
(
prefix_chars
=
'+:-'
)
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
(
'''
\
usage: PROG [-h] [++foo] bar {1,2} ...
usage: PROG [-h] [++foo] bar {1,2
,3
} ...
main description
positional arguments:
bar bar help
{1,2
}
command help
{1,2
,3}
command help
optional arguments:
-h, --help show this help message and exit
...
...
@@ -1865,15 +1877,15 @@ class TestAddSubparsers(TestCase):
def
test_help_alternate_prefix_chars
(
self
):
parser
=
self
.
_get_parser
(
prefix_chars
=
'+:/'
)
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
(
'''
\
usage: PROG [+h] [++foo] bar {1,2} ...
usage: PROG [+h] [++foo] bar {1,2
,3
} ...
main description
positional arguments:
bar bar help
{1,2
}
command help
{1,2
,3}
command help
optional arguments:
+h, ++help show this help message and exit
...
...
@@ -1882,18 +1894,19 @@ class TestAddSubparsers(TestCase):
def
test_parser_command_help
(
self
):
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
(),
textwrap
.
dedent
(
'''
\
usage: PROG [-h] [--foo] bar {1,2} ...
usage: PROG [-h] [--foo] bar {1,2
,3
} ...
main description
positional arguments:
bar bar help
{1,2
}
command help
{1,2
,3}
command help
1 1 help
2 2 help
3 3 help
optional arguments:
-h, --help show this help message and exit
...
...
Misc/ACKS
Dosyayı görüntüle @
68f555c0
...
...
@@ -462,6 +462,7 @@ Thomas Kluyver
Kim Knapp
Lenny Kneler
Pat Knight
Jeff Knupp
Greg Kochanski
Damon Kohler
Marko Kohtala
...
...
Misc/NEWS
Dosyayı görüntüle @
68f555c0
...
...
@@ -90,6 +90,9 @@ Core and Builtins
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 #6493: An issue in ctypes on Windows that caused structure bitfields
...
...
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