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
afce02ed
Kaydet (Commit)
afce02ed
authored
Eki 17, 2014
tarafından
R David Murray
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge: #9351: set_defaults on subparser is no longer ignored if set on parent.
üst
d2ff243b
7570cbdc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
1 deletion
+18
-1
argparse.py
Lib/argparse.py
+8
-1
test_argparse.py
Lib/test/test_argparse.py
+7
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/argparse.py
Dosyayı görüntüle @
afce02ed
...
@@ -1122,7 +1122,14 @@ class _SubParsersAction(Action):
...
@@ -1122,7 +1122,14 @@ class _SubParsersAction(Action):
# parse all the remaining options into the namespace
# parse all the remaining options into the namespace
# store any unrecognized options on the object, so that the top
# store any unrecognized options on the object, so that the top
# level parser can decide what to do with them
# level parser can decide what to do with them
namespace
,
arg_strings
=
parser
.
parse_known_args
(
arg_strings
,
namespace
)
# In case this subparser defines new defaults, we parse them
# in a new namespace object and then update the original
# namespace for the relevant parts.
subnamespace
,
arg_strings
=
parser
.
parse_known_args
(
arg_strings
,
None
)
for
key
,
value
in
vars
(
subnamespace
)
.
items
():
setattr
(
namespace
,
key
,
value
)
if
arg_strings
:
if
arg_strings
:
vars
(
namespace
)
.
setdefault
(
_UNRECOGNIZED_ARGS_ATTR
,
[])
vars
(
namespace
)
.
setdefault
(
_UNRECOGNIZED_ARGS_ATTR
,
[])
getattr
(
namespace
,
_UNRECOGNIZED_ARGS_ATTR
)
.
extend
(
arg_strings
)
getattr
(
namespace
,
_UNRECOGNIZED_ARGS_ATTR
)
.
extend
(
arg_strings
)
...
...
Lib/test/test_argparse.py
Dosyayı görüntüle @
afce02ed
...
@@ -2781,6 +2781,13 @@ class TestSetDefaults(TestCase):
...
@@ -2781,6 +2781,13 @@ class TestSetDefaults(TestCase):
parser
=
ErrorRaisingArgumentParser
(
parents
=
[
parent
])
parser
=
ErrorRaisingArgumentParser
(
parents
=
[
parent
])
self
.
assertEqual
(
NS
(
x
=
'foo'
),
parser
.
parse_args
([]))
self
.
assertEqual
(
NS
(
x
=
'foo'
),
parser
.
parse_args
([]))
def
test_set_defaults_on_parent_and_subparser
(
self
):
parser
=
argparse
.
ArgumentParser
()
xparser
=
parser
.
add_subparsers
()
.
add_parser
(
'X'
)
parser
.
set_defaults
(
foo
=
1
)
xparser
.
set_defaults
(
foo
=
2
)
self
.
assertEqual
(
NS
(
foo
=
2
),
parser
.
parse_args
([
'X'
]))
def
test_set_defaults_same_as_add_argument
(
self
):
def
test_set_defaults_same_as_add_argument
(
self
):
parser
=
ErrorRaisingArgumentParser
()
parser
=
ErrorRaisingArgumentParser
()
parser
.
set_defaults
(
w
=
'W'
,
x
=
'X'
,
y
=
'Y'
,
z
=
'Z'
)
parser
.
set_defaults
(
w
=
'W'
,
x
=
'X'
,
y
=
'Y'
,
z
=
'Z'
)
...
...
Misc/NEWS
Dosyayı görüntüle @
afce02ed
...
@@ -181,6 +181,9 @@ Core and Builtins
...
@@ -181,6 +181,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
9351
:
Defaults
set
with
set_defaults
on
an
argparse
subparser
are
no
longer
ignored
when
also
set
on
the
parent
parser
.
-
Issue
#
21991
:
Make
email
.
headerregistry
's header '
params
' attributes
-
Issue
#
21991
:
Make
email
.
headerregistry
's header '
params
' attributes
be read-only (MappingProxyType). Previously the dictionary was modifiable
be read-only (MappingProxyType). Previously the dictionary was modifiable
but a new one was created on each access of the attribute.
but a new one was created on each access of the attribute.
...
...
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