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
6a973c71
Commit
6a973c71
authored
Mar 31, 2000
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
robustify UserList constructor -- will now accept any sequence
add test cases for non-UserList class, tuple, & string
parent
074c3e62
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
Lib/UserList.py
Lib/UserList.py
+8
-5
Lib/test/test_userlist.py
Lib/test/test_userlist.py
+11
-0
No files found.
Lib/UserList.py
View file @
6a973c71
"""A more or less complete user-defined wrapper around list objects."""
class
UserList
:
def
__init__
(
self
,
list
=
None
):
def
__init__
(
self
,
init
list
=
None
):
self
.
data
=
[]
if
list
is
not
None
:
if
type
(
list
)
==
type
(
self
.
data
):
self
.
data
[:]
=
list
if
initlist
is
not
None
:
# XXX should this accept an arbitary sequence?
if
type
(
initlist
)
==
type
(
self
.
data
):
self
.
data
[:]
=
initlist
elif
isinstance
(
initlist
,
UserList
):
self
.
data
[:]
=
initlist
.
data
[:]
else
:
self
.
data
[:]
=
list
.
data
[:]
self
.
data
=
list
(
initlist
)
def
__repr__
(
self
):
return
repr
(
self
.
data
)
def
__cmp__
(
self
,
other
):
if
isinstance
(
other
,
UserList
):
...
...
Lib/test/test_userlist.py
View file @
6a973c71
...
...
@@ -18,6 +18,17 @@ uu0 = UserList(u0)
uu1
=
UserList
(
u1
)
uu2
=
UserList
(
u2
)
v
=
UserList
(
tuple
(
u
))
class
OtherList
:
def
__init__
(
self
,
initlist
):
self
.
__data
=
initlist
def
__len__
(
self
):
return
len
(
self
.
__data
)
def
__getitem__
(
self
,
i
):
return
self
.
__data
[
i
]
v0
=
UserList
(
OtherList
(
u0
))
vv
=
UserList
(
"this is also a sequence"
)
# Test __repr__
assert
str
(
u0
)
==
str
(
l0
)
...
...
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