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
aa4c36fb
Kaydet (Commit)
aa4c36fb
authored
Mar 26, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #23775: pprint() of OrderedDict now outputs the same representation
as repr().
üst
f3fa3088
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
24 deletions
+40
-24
pprint.py
Lib/pprint.py
+15
-6
test_pprint.py
Lib/test/test_pprint.py
+22
-18
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/pprint.py
Dosyayı görüntüle @
aa4c36fb
...
...
@@ -34,10 +34,10 @@ saferepr()
"""
import
collections
as
_collections
import
re
import
sys
as
_sys
import
types
as
_types
from
collections
import
OrderedDict
as
_OrderedDict
from
io
import
StringIO
as
_StringIO
__all__
=
[
"pprint"
,
"pformat"
,
"isreadable"
,
"isrecursive"
,
"saferepr"
,
...
...
@@ -188,16 +188,25 @@ class PrettyPrinter:
write
((
self
.
_indent_per_level
-
1
)
*
' '
)
length
=
len
(
object
)
if
length
:
if
isinstance
(
object
,
_OrderedDict
):
items
=
list
(
object
.
items
())
else
:
items
=
sorted
(
object
.
items
(),
key
=
_safe_tuple
)
items
=
sorted
(
object
.
items
(),
key
=
_safe_tuple
)
self
.
_format_dict_items
(
items
,
stream
,
indent
,
allowance
+
1
,
context
,
level
)
write
(
'}'
)
_dispatch
[
dict
.
__repr__
]
=
_pprint_dict
_dispatch
[
_OrderedDict
.
__repr__
]
=
_pprint_dict
def
_pprint_ordered_dict
(
self
,
object
,
stream
,
indent
,
allowance
,
context
,
level
):
if
not
len
(
object
):
stream
.
write
(
repr
(
object
))
return
cls
=
object
.
__class__
stream
.
write
(
cls
.
__name__
+
'('
)
self
.
_format
(
list
(
object
.
items
()),
stream
,
indent
+
len
(
cls
.
__name__
)
+
1
,
allowance
+
1
,
context
,
level
)
stream
.
write
(
')'
)
_dispatch
[
_collections
.
OrderedDict
.
__repr__
]
=
_pprint_ordered_dict
def
_pprint_list
(
self
,
object
,
stream
,
indent
,
allowance
,
context
,
level
):
stream
.
write
(
'['
)
...
...
Lib/test/test_pprint.py
Dosyayı görüntüle @
aa4c36fb
...
...
@@ -272,19 +272,23 @@ class QueryTestCase(unittest.TestCase):
r"{5: [[]], 'xy\tab\n': (3,), (): {}}"
)
def
test_ordered_dict
(
self
):
d
=
collections
.
OrderedDict
()
self
.
assertEqual
(
pprint
.
pformat
(
d
,
width
=
1
),
'OrderedDict()'
)
d
=
collections
.
OrderedDict
([])
self
.
assertEqual
(
pprint
.
pformat
(
d
,
width
=
1
),
'OrderedDict()'
)
words
=
'the quick brown fox jumped over a lazy dog'
.
split
()
d
=
collections
.
OrderedDict
(
zip
(
words
,
itertools
.
count
()))
self
.
assertEqual
(
pprint
.
pformat
(
d
),
"""
\
{'the': 0
,
'quick': 1
,
'brown': 2
,
'fox': 3
,
'jumped': 4
,
'over': 5
,
'a': 6
,
'lazy': 7
,
'dog': 8}
"""
)
OrderedDict([('the', 0)
,
('quick', 1)
,
('brown', 2)
,
('fox', 3)
,
('jumped', 4)
,
('over', 5)
,
('a', 6)
,
('lazy', 7)
,
('dog', 8)])
"""
)
def
test_mapping_proxy
(
self
):
words
=
'the quick brown fox jumped over a lazy dog'
.
split
()
...
...
@@ -303,15 +307,15 @@ mappingproxy({'a': 6,
d
=
collections
.
OrderedDict
(
zip
(
words
,
itertools
.
count
()))
m
=
types
.
MappingProxyType
(
d
)
self
.
assertEqual
(
pprint
.
pformat
(
m
),
"""
\
mappingproxy(
{'the': 0
,
'quick': 1
,
'brown': 2
,
'fox': 3
,
'jumped': 4
,
'over': 5
,
'a': 6
,
'lazy': 7
,
'dog': 8}
)"""
)
mappingproxy(
OrderedDict([('the', 0)
,
('quick', 1)
,
('brown', 2)
,
('fox', 3)
,
('jumped', 4)
,
('over', 5)
,
('a', 6)
,
('lazy', 7)
,
('dog', 8)])
)"""
)
def
test_subclassing
(
self
):
o
=
{
'names with spaces'
:
'should be presented using repr()'
,
...
...
Misc/NEWS
Dosyayı görüntüle @
aa4c36fb
...
...
@@ -30,6 +30,9 @@ Core and Builtins
Library
-------
-
Issue
#
23775
:
pprint
()
of
OrderedDict
now
outputs
the
same
representation
as
repr
().
-
Issue
#
23765
:
Removed
IsBadStringPtr
calls
in
ctypes
-
Issue
#
22364
:
Improved
some
re
error
messages
using
regex
for
hints
.
...
...
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