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
51844384
Kaydet (Commit)
51844384
authored
Eki 02, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #19137: The pprint module now correctly formats instances of set and
frozenset subclasses.
üst
224c87d6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
27 deletions
+83
-27
pprint.py
Lib/pprint.py
+13
-15
test_pprint.py
Lib/test/test_pprint.py
+67
-12
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/pprint.py
Dosyayı görüntüle @
51844384
...
...
@@ -205,24 +205,22 @@ class PrettyPrinter:
if
issubclass
(
typ
,
list
):
write
(
'['
)
endchar
=
']'
elif
issubclass
(
typ
,
set
):
if
not
length
:
write
(
'set()'
)
return
write
(
'{'
)
endchar
=
'}'
object
=
sorted
(
object
,
key
=
_safe_key
)
elif
issubclass
(
typ
,
frozenset
):
elif
issubclass
(
typ
,
tuple
):
write
(
'('
)
endchar
=
')'
else
:
if
not
length
:
write
(
'frozenset()'
)
write
(
rep
)
return
write
(
'frozenset({'
)
endchar
=
'})'
if
typ
is
set
:
write
(
'{'
)
endchar
=
'}'
else
:
write
(
typ
.
__name__
)
write
(
'({'
)
endchar
=
'})'
indent
+=
len
(
typ
.
__name__
)
+
1
object
=
sorted
(
object
,
key
=
_safe_key
)
indent
+=
10
else
:
write
(
'('
)
endchar
=
')'
if
self
.
_indent_per_level
>
1
:
write
((
self
.
_indent_per_level
-
1
)
*
' '
)
if
length
:
...
...
Lib/test/test_pprint.py
Dosyayı görüntüle @
51844384
...
...
@@ -21,6 +21,20 @@ class tuple3(tuple):
def
__repr__
(
self
):
return
tuple
.
__repr__
(
self
)
class
set2
(
set
):
pass
class
set3
(
set
):
def
__repr__
(
self
):
return
set
.
__repr__
(
self
)
class
frozenset2
(
frozenset
):
pass
class
frozenset3
(
frozenset
):
def
__repr__
(
self
):
return
frozenset
.
__repr__
(
self
)
class
dict2
(
dict
):
pass
...
...
@@ -115,22 +129,24 @@ class QueryTestCase(unittest.TestCase):
for
simple
in
(
0
,
0
,
0
+
0
j
,
0.0
,
""
,
b
""
,
(),
tuple2
(),
tuple3
(),
[],
list2
(),
list3
(),
set
(),
set2
(),
set3
(),
frozenset
(),
frozenset2
(),
frozenset3
(),
{},
dict2
(),
dict3
(),
self
.
assertTrue
,
pprint
,
-
6
,
-
6
,
-
6
-
6
j
,
-
1.5
,
"x"
,
b
"x"
,
(
3
,),
[
3
],
{
3
:
6
},
(
1
,
2
),
[
3
,
4
],
{
5
:
6
},
tuple2
((
1
,
2
)),
tuple3
((
1
,
2
)),
tuple3
(
range
(
100
)),
[
3
,
4
],
list2
([
3
,
4
]),
list3
([
3
,
4
]),
list3
(
range
(
100
)),
set
({
7
}),
set2
({
7
}),
set3
({
7
}),
frozenset
({
8
}),
frozenset2
({
8
}),
frozenset3
({
8
}),
dict2
({
5
:
6
}),
dict3
({
5
:
6
}),
range
(
10
,
-
11
,
-
1
)
):
native
=
repr
(
simple
)
for
function
in
"pformat"
,
"saferepr"
:
f
=
getattr
(
pprint
,
function
)
got
=
f
(
simple
)
self
.
assertEqual
(
native
,
got
,
"expected
%
s got
%
s from pprint.
%
s"
%
(
native
,
got
,
function
))
self
.
assertEqual
(
pprint
.
pformat
(
simple
),
native
)
self
.
assertEqual
(
pprint
.
pformat
(
simple
,
width
=
1
,
indent
=
0
)
.
replace
(
'
\n
'
,
' '
),
native
)
self
.
assertEqual
(
pprint
.
saferepr
(
simple
),
native
)
def
test_basic_line_wrap
(
self
):
# verify basic line-wrapping operation
...
...
@@ -219,10 +235,54 @@ class QueryTestCase(unittest.TestCase):
others.should.not.be: like.this}"""
self
.
assertEqual
(
DottedPrettyPrinter
()
.
pformat
(
o
),
exp
)
def
test_set_reprs
(
self
):
self
.
assertEqual
(
pprint
.
pformat
(
set
()),
'set()'
)
self
.
assertEqual
(
pprint
.
pformat
(
set
(
range
(
3
))),
'{0, 1, 2}'
)
self
.
assertEqual
(
pprint
.
pformat
(
set
(
range
(
7
)),
width
=
20
),
'''
\
{0,
1,
2,
3,
4,
5,
6}'''
)
self
.
assertEqual
(
pprint
.
pformat
(
set2
(
range
(
7
)),
width
=
20
),
'''
\
set2({0,
1,
2,
3,
4,
5,
6})'''
)
self
.
assertEqual
(
pprint
.
pformat
(
set3
(
range
(
7
)),
width
=
20
),
'set3({0, 1, 2, 3, 4, 5, 6})'
)
self
.
assertEqual
(
pprint
.
pformat
(
frozenset
()),
'frozenset()'
)
self
.
assertEqual
(
pprint
.
pformat
(
frozenset
(
range
(
3
))),
'frozenset({0, 1, 2})'
)
self
.
assertEqual
(
pprint
.
pformat
(
frozenset
(
range
(
7
)),
width
=
20
),
'''
\
frozenset({0,
1,
2,
3,
4,
5,
6})'''
)
self
.
assertEqual
(
pprint
.
pformat
(
frozenset2
(
range
(
7
)),
width
=
20
),
'''
\
frozenset2({0,
1,
2,
3,
4,
5,
6})'''
)
self
.
assertEqual
(
pprint
.
pformat
(
frozenset3
(
range
(
7
)),
width
=
20
),
'frozenset3({0, 1, 2, 3, 4, 5, 6})'
)
@unittest.expectedFailure
#See http://bugs.python.org/issue13907
@test.support.cpython_only
def
test_set_reprs
(
self
):
def
test_set_
of_sets_
reprs
(
self
):
# This test creates a complex arrangement of frozensets and
# compares the pretty-printed repr against a string hard-coded in
# the test. The hard-coded repr depends on the sort order of
...
...
@@ -245,11 +305,6 @@ class QueryTestCase(unittest.TestCase):
# algorithm cause the test to fail when it should pass.
# XXX Or changes to the dictionary implmentation...
self
.
assertEqual
(
pprint
.
pformat
(
set
()),
'set()'
)
self
.
assertEqual
(
pprint
.
pformat
(
set
(
range
(
3
))),
'{0, 1, 2}'
)
self
.
assertEqual
(
pprint
.
pformat
(
frozenset
()),
'frozenset()'
)
self
.
assertEqual
(
pprint
.
pformat
(
frozenset
(
range
(
3
))),
'frozenset({0, 1, 2})'
)
cube_repr_tgt
=
"""
\
{frozenset(): frozenset({frozenset({2}), frozenset({0}), frozenset({1})}),
frozenset({0}): frozenset({frozenset(),
...
...
Misc/NEWS
Dosyayı görüntüle @
51844384
...
...
@@ -71,6 +71,9 @@ Core and Builtins
Library
-------
- Issue #19137: The pprint module now correctly formats instances of set and
frozenset subclasses.
- Issue #19092: contextlib.ExitStack now correctly reraises exceptions
from the __exit__ callbacks of inner context managers (Patch by Hrvoje
Nikšić)
...
...
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