From fc71e94995f56d371d85f8ea82a0c93d3f231d50 Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Sun, 22 Sep 2013 19:44:11 +1000 Subject: [PATCH] The pypy version of the operator module is missing __index__() as alias for index(). --- src/wrappers.py | 14 +++++++------- tests/test_object_proxy.py | 11 ++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/wrappers.py b/src/wrappers.py index 125f507..e48ed9b 100644 --- a/src/wrappers.py +++ b/src/wrappers.py @@ -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__) diff --git a/tests/test_object_proxy.py b/tests/test_object_proxy.py index ca4c900..99f1a91 100644 --- a/tests/test_object_proxy.py +++ b/tests/test_object_proxy.py @@ -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):