The pypy version of the operator module is missing __index__() as alias for index().

This commit is contained in:
Graham Dumpleton
2013-09-22 19:44:11 +10:00
parent bdff638fc1
commit fc71e94995
2 changed files with 13 additions and 12 deletions

View File

@@ -178,10 +178,10 @@ class ObjectProxy(six.with_metaclass(_ObjectProxyMetaType)):
return self.__wrapped__ * other
def __div__(self, other):
return operator.__div__(self.__wrapped__, other)
return operator.div(self.__wrapped__, other)
def __truediv__(self, other):
return operator.__truediv__(self.__wrapped__, other)
return operator.truediv(self.__wrapped__, other)
def __floordiv__(self, other):
return self.__wrapped__ // other
@@ -220,10 +220,10 @@ class ObjectProxy(six.with_metaclass(_ObjectProxyMetaType)):
return other * self.__wrapped__
def __rdiv__(self, other):
return operator.__div__(other, self.__wrapped__)
return operator.div(other, self.__wrapped__)
def __rtruediv__(self, other):
return operator.__truediv__(other, self.__wrapped__)
return operator.truediv(other, self.__wrapped__)
def __rfloordiv__(self, other):
return other // self.__wrapped__
@@ -265,11 +265,11 @@ class ObjectProxy(six.with_metaclass(_ObjectProxyMetaType)):
return self
def __idiv__(self, other):
self.__wrapped__ = operator.__idiv__(self.__wrapped__, other)
self.__wrapped__ = operator.idiv(self.__wrapped__, other)
return self
def __itruediv__(self, other):
self.__wrapped__ = operator.__itruediv__(self.__wrapped__, other)
self.__wrapped__ = operator.itruediv(self.__wrapped__, other)
return self
def __ifloordiv__(self, other):
@@ -332,7 +332,7 @@ class ObjectProxy(six.with_metaclass(_ObjectProxyMetaType)):
return hex(self.__wrapped__)
def __index__(self):
return operator.__index__(self.__wrapped__)
return operator.index(self.__wrapped__)
def __len__(self):
return len(self.__wrapped__)

View File

@@ -1139,12 +1139,13 @@ class TestAsNumberObjectProxy(unittest.TestCase):
self.assertEqual(hex(value), hex(20))
def test_index(self):
value = wrapt.ObjectProxy(20)
class Class(object):
def __index__(self):
return 1
value = wrapt.ObjectProxy(Class())
items = [0, 1, 2]
# PyPy doesn't implement operator.__index__().
if not is_pypy:
self.assertEqual(value.__index__(), operator.__index__(20))
self.assertEqual(items[value], items[1])
class TestAsSequenceObjectProxy(unittest.TestCase):