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
76b1714b
Kaydet (Commit)
76b1714b
authored
Tem 29, 2015
tarafından
Berker Peksag
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #24360: Improve __repr__ of argparse.Namespace() for invalid identifiers.
Patch by Matthias Bussonnier.
üst
ada5578f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
argparse.py
Lib/argparse.py
+7
-1
test_argparse.py
Lib/test/test_argparse.py
+15
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/argparse.py
Dosyayı görüntüle @
76b1714b
...
...
@@ -118,10 +118,16 @@ class _AttributeHolder(object):
def
__repr__
(
self
):
type_name
=
type
(
self
)
.
__name__
arg_strings
=
[]
star_args
=
{}
for
arg
in
self
.
_get_args
():
arg_strings
.
append
(
repr
(
arg
))
for
name
,
value
in
self
.
_get_kwargs
():
arg_strings
.
append
(
'
%
s=
%
r'
%
(
name
,
value
))
if
name
.
isidentifier
():
arg_strings
.
append
(
'
%
s=
%
r'
%
(
name
,
value
))
else
:
star_args
[
name
]
=
value
if
star_args
:
arg_strings
.
append
(
'**
%
s'
%
repr
(
star_args
))
return
'
%
s(
%
s)'
%
(
type_name
,
', '
.
join
(
arg_strings
))
def
_get_kwargs
(
self
):
...
...
Lib/test/test_argparse.py
Dosyayı görüntüle @
76b1714b
...
...
@@ -4512,6 +4512,21 @@ class TestStrings(TestCase):
string
=
"Namespace(bar='spam', foo=42)"
self
.
assertStringEqual
(
ns
,
string
)
def
test_namespace_starkwargs_notidentifier
(
self
):
ns
=
argparse
.
Namespace
(
**
{
'"'
:
'quote'
})
string
=
"""Namespace(**{'"': 'quote'})"""
self
.
assertStringEqual
(
ns
,
string
)
def
test_namespace_kwargs_and_starkwargs_notidentifier
(
self
):
ns
=
argparse
.
Namespace
(
a
=
1
,
**
{
'"'
:
'quote'
})
string
=
"""Namespace(a=1, **{'"': 'quote'})"""
self
.
assertStringEqual
(
ns
,
string
)
def
test_namespace_starkwargs_identifier
(
self
):
ns
=
argparse
.
Namespace
(
**
{
'valid'
:
True
})
string
=
"Namespace(valid=True)"
self
.
assertStringEqual
(
ns
,
string
)
def
test_parser
(
self
):
parser
=
argparse
.
ArgumentParser
(
prog
=
'PROG'
)
string
=
(
...
...
Misc/NEWS
Dosyayı görüntüle @
76b1714b
...
...
@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
- Issue #24360: Improve __repr__ of argparse.Namespace() for invalid
identifiers. Patch by Matthias Bussonnier.
- Issue #23319: Fix ctypes.BigEndianStructure, swap correctly bytes. Patch
written by Matthieu Gautier.
...
...
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