Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1453e4aa
Commit
1453e4aa
authored
May 21, 2004
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* teach repr.repr() about collections.deque()
* rename a variable for clarity
parent
ba6cd364
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
Lib/repr.py
Lib/repr.py
+6
-2
Lib/test/test_repr.py
Lib/test/test_repr.py
+4
-0
No files found.
Lib/repr.py
View file @
1453e4aa
...
...
@@ -15,6 +15,7 @@ class Repr:
self
.
maxdict
=
4
self
.
maxset
=
6
self
.
maxfrozenset
=
6
self
.
maxdeque
=
6
self
.
maxstring
=
30
self
.
maxlong
=
40
self
.
maxother
=
20
...
...
@@ -37,7 +38,7 @@ class Repr:
s
=
s
[:
i
]
+
'...'
+
s
[
len
(
s
)
-
j
:]
return
s
def
_repr_iterable
(
self
,
x
,
level
,
left
,
right
,
maxiter
,
fina
l
=
''
):
def
_repr_iterable
(
self
,
x
,
level
,
left
,
right
,
maxiter
,
trai
l
=
''
):
n
=
len
(
x
)
if
level
<=
0
and
n
:
s
=
'...'
...
...
@@ -47,7 +48,7 @@ class Repr:
pieces
=
[
repr1
(
elem
,
newlevel
)
for
elem
in
islice
(
x
,
maxiter
)]
if
n
>
maxiter
:
pieces
.
append
(
'...'
)
s
=
', '
.
join
(
pieces
)
if
n
==
1
and
final
:
s
+=
final
if
n
==
1
and
trail
:
right
=
trail
+
right
return
'%s%s%s'
%
(
left
,
s
,
right
)
def
repr_tuple
(
self
,
x
,
level
):
...
...
@@ -67,6 +68,9 @@ class Repr:
return
self
.
_repr_iterable
(
x
,
level
,
'frozenset(['
,
'])'
,
self
.
maxfrozenset
)
def
repr_deque
(
self
,
x
,
level
):
return
self
.
_repr_iterable
(
x
,
level
,
'deque(['
,
'])'
,
self
.
maxdeque
)
def
repr_dict
(
self
,
x
,
level
):
n
=
len
(
x
)
if
n
==
0
:
return
'{}'
...
...
Lib/test/test_repr.py
View file @
1453e4aa
...
...
@@ -35,6 +35,7 @@ class ReprTests(unittest.TestCase):
def
test_container
(
self
):
from
array
import
array
from
collections
import
deque
eq
=
self
.
assertEquals
# Tuples give up after 6 elements
...
...
@@ -65,6 +66,9 @@ class ReprTests(unittest.TestCase):
eq
(
r
(
frozenset
([
1
,
2
,
3
,
4
,
5
,
6
])),
"frozenset([1, 2, 3, 4, 5, 6])"
)
eq
(
r
(
frozenset
([
1
,
2
,
3
,
4
,
5
,
6
,
7
])),
"frozenset([1, 2, 3, 4, 5, 6, ...])"
)
# collections.deque after 6
eq
(
r
(
deque
([
1
,
2
,
3
,
4
,
5
,
6
,
7
])),
"deque([1, 2, 3, 4, 5, 6, ...])"
)
# Dictionaries give up after 4.
eq
(
r
({}),
"{}"
)
d
=
{
'alice'
:
1
,
'bob'
:
2
,
'charles'
:
3
,
'dave'
:
4
}
...
...
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