1.1 --- a/lib/__builtins__/sequence.py Tue Nov 29 23:12:15 2016 +0100
1.2 +++ b/lib/__builtins__/sequence.py Tue Nov 29 23:13:18 2016 +0100
1.3 @@ -62,6 +62,19 @@
1.4
1.5 return False
1.6
1.7 + def index(self, value):
1.8 +
1.9 + "Return the index of 'value' or raise ValueError."
1.10 +
1.11 + i = 0
1.12 + l = len(self)
1.13 + while i < l:
1.14 + if self[i] == value:
1.15 + return i
1.16 + i += 1
1.17 +
1.18 + raise ValueError(value)
1.19 +
1.20 def __getitem__(self, index):
1.21
1.22 "Return the item or slice specified by 'index'."
1.23 @@ -81,7 +94,7 @@
1.24 # No other kinds of objects are supported as indexes.
1.25
1.26 else:
1.27 - raise TypeError
1.28 + raise TypeError()
1.29
1.30 def __setitem__(self, index, value):
1.31
1.32 @@ -102,7 +115,7 @@
1.33 # No other kinds of objects are supported as indexes.
1.34
1.35 else:
1.36 - raise TypeError
1.37 + raise TypeError()
1.38
1.39 def __getslice__(self, start, end=None):
1.40
2.1 --- a/tests/list.py Tue Nov 29 23:12:15 2016 +0100
2.2 +++ b/tests/list.py Tue Nov 29 23:13:18 2016 +0100
2.3 @@ -33,3 +33,11 @@
2.4 print 4 not in l # True
2.5 print "four" not in l # False
2.6 print "one" not in l # True
2.7 +
2.8 +print l.index(1) # 0
2.9 +print l.index("four") # 3
2.10 +
2.11 +try:
2.12 + print l.index(4) # should raise an exception
2.13 +except ValueError, exc:
2.14 + print "l.index(4): failed to find argument", exc.value