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
8fd3ecf9
Kaydet (Commit)
8fd3ecf9
authored
Eyl 12, 2007
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Bug #1153: repr.repr() now doesn't require set and dictionary items
to be orderable to properly represent them.
üst
c28d5fb4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
5 deletions
+28
-5
repr.py
Lib/repr.py
+15
-5
test_repr.py
Lib/test/test_repr.py
+10
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/repr.py
Dosyayı görüntüle @
8fd3ecf9
"""Redo the
`...`
(representation) but with limits on most sizes."""
"""Redo the
builtin repr()
(representation) but with limits on most sizes."""
__all__
=
[
"Repr"
,
"repr"
]
__all__
=
[
"Repr"
,
"repr"
]
...
@@ -62,11 +62,11 @@ class Repr:
...
@@ -62,11 +62,11 @@ class Repr:
return
self
.
_repr_iterable
(
x
,
level
,
header
,
'])'
,
self
.
maxarray
)
return
self
.
_repr_iterable
(
x
,
level
,
header
,
'])'
,
self
.
maxarray
)
def
repr_set
(
self
,
x
,
level
):
def
repr_set
(
self
,
x
,
level
):
x
=
sorted
(
x
)
x
=
_possibly_
sorted
(
x
)
return
self
.
_repr_iterable
(
x
,
level
,
'set(['
,
'])'
,
self
.
maxset
)
return
self
.
_repr_iterable
(
x
,
level
,
'set(['
,
'])'
,
self
.
maxset
)
def
repr_frozenset
(
self
,
x
,
level
):
def
repr_frozenset
(
self
,
x
,
level
):
x
=
sorted
(
x
)
x
=
_possibly_
sorted
(
x
)
return
self
.
_repr_iterable
(
x
,
level
,
'frozenset(['
,
'])'
,
return
self
.
_repr_iterable
(
x
,
level
,
'frozenset(['
,
'])'
,
self
.
maxfrozenset
)
self
.
maxfrozenset
)
...
@@ -80,7 +80,7 @@ class Repr:
...
@@ -80,7 +80,7 @@ class Repr:
newlevel
=
level
-
1
newlevel
=
level
-
1
repr1
=
self
.
repr1
repr1
=
self
.
repr1
pieces
=
[]
pieces
=
[]
for
key
in
islice
(
sorted
(
x
),
self
.
maxdict
):
for
key
in
islice
(
_possibly_
sorted
(
x
),
self
.
maxdict
):
keyrepr
=
repr1
(
key
,
newlevel
)
keyrepr
=
repr1
(
key
,
newlevel
)
valrepr
=
repr1
(
x
[
key
],
newlevel
)
valrepr
=
repr1
(
x
[
key
],
newlevel
)
pieces
.
append
(
'
%
s:
%
s'
%
(
keyrepr
,
valrepr
))
pieces
.
append
(
'
%
s:
%
s'
%
(
keyrepr
,
valrepr
))
...
@@ -110,7 +110,7 @@ class Repr:
...
@@ -110,7 +110,7 @@ class Repr:
s
=
__builtin__
.
repr
(
x
)
s
=
__builtin__
.
repr
(
x
)
# Bugs in x.__repr__() can cause arbitrary
# Bugs in x.__repr__() can cause arbitrary
# exceptions -- then make up something
# exceptions -- then make up something
except
:
except
Exception
:
return
'<
%
s instance at
%
x>'
%
(
x
.
__class__
.
__name__
,
id
(
x
))
return
'<
%
s instance at
%
x>'
%
(
x
.
__class__
.
__name__
,
id
(
x
))
if
len
(
s
)
>
self
.
maxstring
:
if
len
(
s
)
>
self
.
maxstring
:
i
=
max
(
0
,
(
self
.
maxstring
-
3
)
//
2
)
i
=
max
(
0
,
(
self
.
maxstring
-
3
)
//
2
)
...
@@ -118,5 +118,15 @@ class Repr:
...
@@ -118,5 +118,15 @@ class Repr:
s
=
s
[:
i
]
+
'...'
+
s
[
len
(
s
)
-
j
:]
s
=
s
[:
i
]
+
'...'
+
s
[
len
(
s
)
-
j
:]
return
s
return
s
def
_possibly_sorted
(
x
):
# Since not all sequences of items can be sorted and comparison
# functions may raise arbitrary exceptions, return an unsorted
# sequence in that case.
try
:
return
sorted
(
x
)
except
Exception
:
return
list
(
x
)
aRepr
=
Repr
()
aRepr
=
Repr
()
repr
=
aRepr
.
repr
repr
=
aRepr
.
repr
Lib/test/test_repr.py
Dosyayı görüntüle @
8fd3ecf9
...
@@ -196,6 +196,16 @@ class ReprTests(unittest.TestCase):
...
@@ -196,6 +196,16 @@ class ReprTests(unittest.TestCase):
x
=
classmethod
(
C
.
foo
)
x
=
classmethod
(
C
.
foo
)
self
.
failUnless
(
repr
(
x
)
.
startswith
(
'<classmethod object at 0x'
))
self
.
failUnless
(
repr
(
x
)
.
startswith
(
'<classmethod object at 0x'
))
def
test_unsortable
(
self
):
# Repr.repr() used to call sorted() on sets, frozensets and dicts
# without taking into account that not all objects are comparable
x
=
set
([
1
j
,
2
j
,
3
j
])
y
=
frozenset
(
x
)
z
=
{
1
j
:
1
,
2
j
:
2
}
r
(
x
)
r
(
y
)
r
(
z
)
def
touch
(
path
,
text
=
''
):
def
touch
(
path
,
text
=
''
):
fp
=
open
(
path
,
'w'
)
fp
=
open
(
path
,
'w'
)
fp
.
write
(
text
)
fp
.
write
(
text
)
...
...
Misc/NEWS
Dosyayı görüntüle @
8fd3ecf9
...
@@ -255,6 +255,9 @@ Core and builtins
...
@@ -255,6 +255,9 @@ Core and builtins
Library
Library
-------
-------
- Bug #1153: repr.repr() now doesn'
t
require
set
and
dictionary
items
to
be
orderable
to
properly
represent
them
.
-
A
'c_longdouble'
type
was
added
to
the
ctypes
module
.
-
A
'c_longdouble'
type
was
added
to
the
ctypes
module
.
-
Bug
#
1709599
:
Run
test_1565150
only
if
the
file
system
is
NTFS
.
-
Bug
#
1709599
:
Run
test_1565150
only
if
the
file
system
is
NTFS
.
...
...
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