Author: Antonio Cuni <[email protected]>
Branch: int_w-refactor
Changeset: r69432:dc1874f92984
Date: 2014-02-25 17:54 +0100
http://bitbucket.org/pypy/pypy/changeset/dc1874f92984/
Log: add a passing test and a comment explaining why the test was not
failing
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1262,7 +1262,10 @@
raise oefmt(self.w_TypeError, "%s must be an integer, not %T",
objdescr, w_obj)
try:
- index = self.int_w(w_index)
+ # allow_conversion=False it's not really necessary because the
+ # return type of __index__ is already checked by space.index(),
+ # but there is no reason to allow conversions anyway
+ index = self.int_w(w_index, allow_conversion=False)
except OperationError, err:
if not err.match(self, self.w_OverflowError):
raise
diff --git a/pypy/objspace/std/test/test_listobject.py
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -842,6 +842,26 @@
except TypeError:
pass
+ def test_mul___index__(self):
+ class MyInt(object):
+ def __init__(self, x):
+ self.x = x
+
+ def __int__(self):
+ return self.x
+
+ class MyIndex(object):
+ def __init__(self, x):
+ self.x = x
+
+ def __index__(self):
+ return self.x
+
+ assert [0] * MyIndex(3) == [0, 0, 0]
+ raises(TypeError, "[0]*MyInt(3)")
+ raises(TypeError, "[0]*MyIndex(MyInt(3))")
+
+
def test_index(self):
c = range(10)
assert c.index(0) == 0
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit