[pypy-commit] pypy default: rename this function to be non-official. it can lead to bugs because the caller
cfbolz
noreply at buildbot.pypy.org
Fri Nov 4 10:50:26 CET 2011
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch:
Changeset: r48735:2e617066124d
Date: 2011-11-03 21:48 +0100
http://bitbucket.org/pypy/pypy/changeset/2e617066124d/
Log: rename this function to be non-official. it can lead to bugs because
the caller has to check for None
diff --git a/pypy/objspace/std/sliceobject.py b/pypy/objspace/std/sliceobject.py
--- a/pypy/objspace/std/sliceobject.py
+++ b/pypy/objspace/std/sliceobject.py
@@ -4,7 +4,7 @@
from pypy.interpreter import gateway
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.slicetype import eval_slice_index
+from pypy.objspace.std.slicetype import _eval_slice_index
class W_SliceObject(W_Object):
from pypy.objspace.std.slicetype import slice_typedef as typedef
@@ -25,7 +25,7 @@
if space.is_w(w_slice.w_step, space.w_None):
step = 1
else:
- step = eval_slice_index(space, w_slice.w_step)
+ step = _eval_slice_index(space, w_slice.w_step)
if step == 0:
raise OperationError(space.w_ValueError,
space.wrap("slice step cannot be zero"))
@@ -35,7 +35,7 @@
else:
start = 0
else:
- start = eval_slice_index(space, w_slice.w_start)
+ start = _eval_slice_index(space, w_slice.w_start)
if start < 0:
start += length
if start < 0:
@@ -54,7 +54,7 @@
else:
stop = length
else:
- stop = eval_slice_index(space, w_slice.w_stop)
+ stop = _eval_slice_index(space, w_slice.w_stop)
if stop < 0:
stop += length
if stop < 0:
diff --git a/pypy/objspace/std/slicetype.py b/pypy/objspace/std/slicetype.py
--- a/pypy/objspace/std/slicetype.py
+++ b/pypy/objspace/std/slicetype.py
@@ -15,7 +15,9 @@
' normal slices.')
# utility functions
-def eval_slice_index(space, w_int):
+def _eval_slice_index(space, w_int):
+ # note that it is the *callers* responsibility to check for w_None
+ # otherwise you can get funny error messages
try:
return space.getindex_w(w_int, None) # clamp if long integer too large
except OperationError, err:
@@ -26,7 +28,7 @@
"None or have an __index__ method"))
def adapt_lower_bound(space, size, w_index):
- index = eval_slice_index(space, w_index)
+ index = _eval_slice_index(space, w_index)
if index < 0:
index = index + size
if index < 0:
More information about the pypy-commit
mailing list