summaryrefslogtreecommitdiffstats
path: root/Lib/UserList.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-03-31 00:17:46 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-03-31 00:17:46 (GMT)
commit6a973c711823f64d0362d0ba4b25ead4162df357 (patch)
treeb1042df5f08c5414f024849c381da0e964f069b8 /Lib/UserList.py
parent074c3e62d155349a69442f43e81a73883f222ea9 (diff)
downloadcpython-6a973c711823f64d0362d0ba4b25ead4162df357.zip
cpython-6a973c711823f64d0362d0ba4b25ead4162df357.tar.gz
cpython-6a973c711823f64d0362d0ba4b25ead4162df357.tar.bz2
robustify UserList constructor -- will now accept any sequence
add test cases for non-UserList class, tuple, & string
Diffstat (limited to 'Lib/UserList.py')
-rw-r--r--Lib/UserList.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/UserList.py b/Lib/UserList.py
index 1680327..7bd0298 100644
--- a/Lib/UserList.py
+++ b/Lib/UserList.py
@@ -1,13 +1,16 @@
"""A more or less complete user-defined wrapper around list objects."""
class UserList:
- def __init__(self, list=None):
+ def __init__(self, initlist=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):