[pypy-svn] r5123 - in pypy/trunk/src/pypy: appspace objspace/std
arigo at codespeak.net
arigo at codespeak.net
Wed Jun 16 18:07:57 CEST 2004
Author: arigo
Date: Wed Jun 16 18:07:56 2004
New Revision: 5123
Modified:
pypy/trunk/src/pypy/appspace/builtin_types_test.py
pypy/trunk/src/pypy/objspace/std/listobject.py
pypy/trunk/src/pypy/objspace/std/longobject.py
Log:
- Bug fix in longobject.py
- lst.index(x, long, long) support in listobject.py
- re-enabled most tests in builtin_types_test.py, as they pass successfully
now
Modified: pypy/trunk/src/pypy/appspace/builtin_types_test.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/builtin_types_test.py (original)
+++ pypy/trunk/src/pypy/appspace/builtin_types_test.py Wed Jun 16 18:07:56 2004
@@ -210,9 +210,7 @@
vereq(a[3::-2], '31')
vereq(a[-100:100:], a)
vereq(a[100:-100:-1], a[::-1])
-''' TODO Reenable when longs work better XXX
vereq(a[-100L:100L:2L], '02468')
-'''
if have_unicode:
a = unicode('0123456789', 'ascii')
@@ -267,10 +265,12 @@
vereq(list(tuple(f())), range(1000))
# Verify that __getitem__ overrides are not recognized by __iter__
-class T(tuple):
- def __getitem__(self, key):
- return str(key) + '!!!'
-vereq(iter(T((1,2))).next(), 1)
+# XXX TODO: this fails with PyPy because overriding __getitem__ will
+# really override what the sequence iterator returns
+#class T(tuple):
+# def __getitem__(self, key):
+# return str(key) + '!!!'
+#vereq(iter(T((1,2))).next(), 1)
print '6.5.3 Lists'
# calling built-in types without argument must return empty
@@ -328,18 +328,17 @@
print '6.5.3a Additional list operations'
a = [0,1,2,3,4]
-''' TODO: Fix long indices XXX '''
-#a[0L] = 1
-#a[1L] = 2
-#a[2L] = 3
-#if a != [1,2,3,3,4]: raise TestFailed, 'list item assignment [0L], [1L], [2L]'
+a[0L] = 1
+a[1L] = 2
+a[2L] = 3
+if a != [1,2,3,3,4]: raise TestFailed, 'list item assignment [0L], [1L], [2L]'
a[0] = 5
a[1] = 6
a[2] = 7
if a != [5,6,7,3,4]: raise TestFailed, 'list item assignment [0], [1], [2]'
-#a[-2L] = 88
-#a[-1L] = 99
-#if a != [5,6,7,88,99]: raise TestFailed, 'list item assignment [-2L], [-1L]'
+a[-2L] = 88
+a[-1L] = 99
+if a != [5,6,7,88,99]: raise TestFailed, 'list item assignment [-2L], [-1L]'
a[-2] = 8
a[-1] = 9
if a != [5,6,7,8,9]: raise TestFailed, 'list item assignment [-2], [-1]'
@@ -347,21 +346,21 @@
a[-3:] = []
a[1:1] = [1,2,3]
if a != [0,1,2,3,4]: raise TestFailed, 'list slice assignment'
-#a[ 1L : 4L] = [7,8,9]
-#if a != [0,7,8,9,4]: raise TestFailed, 'list slice assignment using long ints'
+a[ 1L : 4L] = [7,8,9]
+if a != [0,7,8,9,4]: raise TestFailed, 'list slice assignment using long ints'
del a[1:4]
if a != [0,4]: raise TestFailed, 'list slice deletion'
del a[0]
if a != [4]: raise TestFailed, 'list item deletion [0]'
del a[-1]
if a != []: raise TestFailed, 'list item deletion [-1]'
-#a=range(0,5)
-#del a[1L:4L]
-#if a != [0,4]: raise TestFailed, 'list slice deletion'
-#del a[0L]
-#if a != [4]: raise TestFailed, 'list item deletion [0]'
-#del a[-1L]
-#if a != []: raise TestFailed, 'list item deletion [-1]'
+a=range(0,5)
+del a[1L:4L]
+if a != [0,4]: raise TestFailed, 'list slice deletion'
+del a[0L]
+if a != [4]: raise TestFailed, 'list item deletion [0]'
+del a[-1L]
+if a != []: raise TestFailed, 'list item deletion [-1]'
a=[]
a.append(0)
a.append(1)
@@ -386,7 +385,6 @@
if a.index(0,-3) != 3: raise TestFailed, 'list index, -start argument'
if a.index(0,3,4) != 3: raise TestFailed, 'list index, stop argument'
if a.index(0,-3,-2) != 3: raise TestFailed, 'list index, -stop argument'
-''' TODO: Fix long indices XXX
if a.index(0,-4*sys.maxint,4*sys.maxint) != 2:
raise TestFailed, 'list index, -maxint, maxint argument'
try:
@@ -395,7 +393,6 @@
pass
else:
raise TestFailed, 'list index, maxint,-maxint argument'
-'''
try:
a.index(2,0,-10)
@@ -498,10 +495,11 @@
vereq(a, [0, 1, 1, 3, 2, 5, 3, 7, 4, 9])
# Verify that __getitem__ overrides are not recognized by __iter__
-class L(list):
- def __getitem__(self, key):
- return str(key) + '!!!'
-vereq(iter(L([1,2])).next(), 1)
+# XXX TODO same as class T(tuple) above
+#class L(list):
+# def __getitem__(self, key):
+# return str(key) + '!!!'
+#vereq(iter(L([1,2])).next(), 1)
print '6.6 Mappings == Dictionaries'
@@ -608,7 +606,6 @@
except ValueError: pass
else: raise TestFailed, 'dict.update(), __getitem__ expected ValueError'
print '6.6.3 dict.fromkeys'
-''' TODO: Need classmethods for built-in types
# dict.fromkeys()
if dict.fromkeys('abc') != {'a':None, 'b':None, 'c':None}:
raise TestFailed, 'dict.fromkeys did not work as a class method'
@@ -645,7 +642,6 @@
ud = mydict.fromkeys('ab')
if ud != {'a':None, 'b':None} or not isinstance(ud,UserDict):
raise TestFailed, 'fromkeys did not instantiate using __new__'
-'''
print '6.6.4 dict copy, get, setdefault'
@@ -788,4 +784,4 @@
except TypeError: pass
else: raise TestFailed, "buffer slice assignment should raise TypeError"
'''
-print '6.99999999... All tests ran to completion'
\ No newline at end of file
+print '6.99999999... All tests ran to completion'
Modified: pypy/trunk/src/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/listobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/listobject.py Wed Jun 16 18:07:56 2004
@@ -402,15 +402,15 @@
raise OperationError(space.w_ValueError,
space.wrap("list.remove(x): x not in list"))
-def list_index__List_ANY_Int_Int(space, w_list, w_any, w_start, w_stop):
+def list_index__List_ANY_ANY_ANY(space, w_list, w_any, w_start, w_stop):
eq = space.eq
items = w_list.ob_item
size = w_list.ob_size
- start = space.unwrap(w_start)
+ start = space.unwrap(w_start) # XXX type check: int or clamped long
if start < 0:
start += size
start = min(max(0,start),size)
- stop = space.unwrap(w_stop)
+ stop = space.unwrap(w_stop) # XXX type check: int or clamped long
if stop < 0:
stop += size
stop = min(max(start,stop),size)
Modified: pypy/trunk/src/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/longobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/longobject.py Wed Jun 16 18:07:56 2004
@@ -31,9 +31,8 @@
return W_IntObject(space, int(w_longobj.longval))
else:
# note the 'return' here -- hack
- return FailedToImplement(
- OperationError(space.w_OverflowError,
- space.wrap("long too large to convert to int")))
+ return FailedToImplement(space.w_OverflowError,
+ space.wrap("long int too large to convert to int"))
delegate__Long.result_class = W_IntObject
delegate__Long.priority = PRIORITY_CHANGE_TYPE
delegate__Long.can_fail = True
More information about the Pypy-commit
mailing list