Commits

Philip Jenvey committed 1d3ff89

remove is{Callable,Mapping,Sequence}Type, sequenceIncludes, repeat/irepeat and
div/idiv. reuse repeat's tests for mul

  • Participants
  • Parent commits cc2ce7a
  • Branches py3k

Comments (0)

Files changed (4)

File pypy/module/operator/__init__.py

 
     appleveldefs = {} 
     
-    app_names = ['__repeat__', 'countOf', 'indexOf',
-                 'isMappingType', 'isNumberType', 'isSequenceType',
-                 'repeat', 'attrgetter', 'itemgetter', 'methodcaller',
+    app_names = ['countOf', 'indexOf',
+                 'attrgetter', 'itemgetter', 'methodcaller',
              ]
 
     for name in app_names:
         appleveldefs[name] = 'app_operator.%s' % name
 
     interp_names = ['index', 'abs', 'add', 'and_',
-                    'concat', 'contains', 'delitem', 'div', 'eq', 'floordiv',
+                    'concat', 'contains', 'delitem', 'eq', 'floordiv',
                     'ge', 'getitem', 'gt', 'inv',
-                    'invert', 'is_', 'is_not', 'isCallable',
+                    'invert', 'is_', 'is_not',
                     'le', 'lshift', 'lt', 'mod', 'mul',
                     'ne', 'neg', 'not_', 'or_',
-                    'pos', 'pow', 'rshift', 'setitem', 'sequenceIncludes',
+                    'pos', 'pow', 'rshift', 'setitem',
                     'sub', 'truediv', 'truth', 'xor',
-                    'iadd', 'iand', 'iconcat', 'idiv', 'ifloordiv',
-                    'ilshift', 'imod', 'imul', 'ior', 'ipow', 'irepeat',
+                    'iadd', 'iand', 'iconcat', 'ifloordiv',
+                    'ilshift', 'imod', 'imul', 'ior', 'ipow',
                     'irshift', 'isub', 'itruediv', 'ixor']
 
     interpleveldefs = {}
     '__and__' : 'and_',
     '__concat__' : 'concat',
     '__contains__' : 'contains',
-    'sequenceIncludes' : 'contains',
     '__delitem__' : 'delitem',
-    '__div__' : 'div',
     '__eq__' : 'eq',
     '__floordiv__' : 'floordiv',
     '__ge__' : 'ge',
     '__iadd__' : 'iadd',
     '__iand__' : 'iand',
     '__iconcat__' : 'iconcat',
-    '__idiv__' : 'idiv',
     '__ifloordiv__' : 'ifloordiv',
     '__ilshift__' : 'ilshift',
     '__imod__' : 'imod',
     '__imul__' : 'imul',
     '__ior__' : 'ior',
     '__ipow__' : 'ipow',
-    '__irepeat__' : 'irepeat',
     '__irshift__' : 'irshift',
     '__isub__' : 'isub',
     '__itruediv__' : 'itruediv',

File pypy/module/operator/app_operator.py

         index += 1
     raise ValueError('sequence.index(x): x not in sequence')
 
-# XXX the following is approximative
-def isMappingType(obj,):
-    'isMappingType(a) -- Return True if a has a mapping type, False otherwise.'
-    # XXX this is fragile and approximative anyway
-    return hasattr(obj, '__getitem__') and hasattr(obj, 'keys')
-
-def isNumberType(obj,):
-    'isNumberType(a) -- Return True if a has a numeric type, False otherwise.'
-    return hasattr(obj, '__int__') or hasattr(obj, '__float__')
-
-def isSequenceType(obj,):
-    'isSequenceType(a) -- Return True if a has a sequence type, False otherwise.'
-    return hasattr(obj, '__getitem__') and not hasattr(obj, 'keys')
-
-def repeat(obj, num):
-    'repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.'
-    if not isinstance(num, int):
-        raise TypeError('an integer is required')
-    if not isSequenceType(obj):
-        raise TypeError("non-sequence object can't be repeated")
-
-    return obj * num
-
-__repeat__ = repeat
-
 
 def attrgetter(attr, *attrs):
     if attrs:

File pypy/module/operator/interp_operator.py

     'delitem(a,b) -- Same as del a[b]'
     space.delitem(w_obj, w_key)
 
-def div(space, w_a, w_b):
-    'div(a, b) -- Same as a / b when __future__.division is no in effect'
-    return space.div(w_a, w_b)
-
 def eq(space, w_a, w_b):
     'eq(a, b) -- Same as a==b'
     return space.eq(w_a, w_b)
     'invert(a) -- Same as ~a.'
     return space.invert(w_obj) 
 
-def isCallable(space, w_obj):
-    'isCallable(a) -- Same as callable(a).'
-    return space.callable(w_obj)
-
-# isMappingType
-
-# isNumberType
-
-# isSequenceType
-
 def is_(space, w_a, w_b):
     'is_(a,b) -- Same as a is b'
     return space.is_(w_a, w_b)
     'pow(a, b) -- Same as a**b.'
     return space.pow(w_a, w_b, space.w_None)
 
-# repeat
-
 def rshift(space, w_a, w_b):
     'rshift(a, b) -- Same as a >> b.'
     return space.rshift(w_a, w_b) 
 
-# sequenceIncludes
-
 def setitem(space, w_obj, w_key, w_value):
     'setitem(a, b, c) -- Same as a[b] = c.'
     space.setitem(w_obj, w_key, w_value)
     'iand(a, b) -- Same as a =& b'
     return space.inplace_and(w_obj1, w_obj2)
 
-def idiv(space, w_a, w_b):
-    'idiv(a, b) -- Same as a /= b when __future__.division is no in effect'
-    return space.inplace_div(w_a, w_b)
-
 def ifloordiv(space, w_a, w_b):
     'ifloordiv(a, b) -- Same as a //= b.'
     return space.inplace_floordiv(w_a, w_b)
         raise OperationError(space.w_TypeError, space.w_None)
 
     return space.inplace_add(w_obj1, w_obj2)
-
-def irepeat(space, w_obj1, w_obj2):
-    'irepeat(a, b) -- Same as a *= b, for a and b sequences.'
-    if space.lookup(w_obj1, '__getitem__') is None:
-        # first arg has to be a sequence
-        raise OperationError(space.w_TypeError,
-                           space.wrap("non-sequence object can't be repeated"))
-
-    if not space.is_true(space.isinstance(w_obj2, space.w_int)):
-        # second arg has to be int/long
-        raise OperationError(space.w_TypeError,
-                             space.wrap('an integer is required'))
-
-    return space.inplace_mul(w_obj1, w_obj2)
-

File pypy/module/operator/test/test_operator.py

         assert operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7]
         raises(TypeError, operator.concat, 13, 29)
 
-    def test_repeat(self):
+    def test_mul(self):
         class Seq1:
             def __init__(self, lst):
                 self.lst = lst
         import operator
 
         a = list(range(3))
-        raises(TypeError, operator.repeat)
-        raises(TypeError, operator.repeat, a, None)
-        assert operator.repeat(a, 2) == a+a
-        assert operator.repeat(a, 1) == a
-        assert operator.repeat(a, 0) == []
+        raises(TypeError, operator.mul)
+        raises(TypeError, operator.mul, a, None)
+        assert operator.mul(a, 2) == a+a
+        assert operator.mul(a, 1) == a
+        assert operator.mul(a, 0) == []
         a = (1, 2, 3)
-        assert operator.repeat(a, 2) == a+a
-        assert operator.repeat(a, 1) == a
-        assert operator.repeat(a, 0) == ()
+        assert operator.mul(a, 2) == a+a
+        assert operator.mul(a, 1) == a
+        assert operator.mul(a, 0) == ()
         a = '123'
-        assert operator.repeat(a, 2) == a+a
-        assert operator.repeat(a, 1) == a
-        assert operator.repeat(a, 0) == ''
+        assert operator.mul(a, 2) == a+a
+        assert operator.mul(a, 1) == a
+        assert operator.mul(a, 0) == ''
         a = Seq1([4, 5, 6])
-        assert operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]
-        assert operator.repeat(a, 1) == [4, 5, 6]
-        assert operator.repeat(a, 0) == []
+        assert operator.mul(a, 2) == [4, 5, 6, 4, 5, 6]
+        assert operator.mul(a, 1) == [4, 5, 6]
+        assert operator.mul(a, 0) == []
         a = Seq2([4, 5, 6])
-        assert operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]
-        assert operator.repeat(a, 1) == [4, 5, 6]
-        assert operator.repeat(a, 0) == []
-        raises(TypeError, operator.repeat, 6, 7)
+        assert operator.mul(a, 2) == [4, 5, 6, 4, 5, 6]
+        assert operator.mul(a, 1) == [4, 5, 6]
+        assert operator.mul(a, 0) == []
 
-    def test_isSequenceType(self):
-        import operator
-
-        raises(TypeError, operator.isSequenceType)
-        assert operator.isSequenceType(dir())
-        assert operator.isSequenceType(())
-        assert operator.isSequenceType(range(10))
-        assert operator.isSequenceType('yeahbuddy')
-        assert not operator.isSequenceType(3)
-        class Dict(dict): pass
-        assert not operator.isSequenceType(Dict())
-
-    def test_inplace(self):
+    def test_iadd(self):
         import operator
 
         list = []
         assert operator.iadd(list, [1, 2]) is list
         assert list == [1, 2]
 
-        list = [1, 2]
-        assert operator.imul(list, 2) is list
-        assert list == [1, 2, 1, 2]
-
-    def test_irepeat(self):
+    def test_imul(self):
         import operator
 
         class X(object):
                 return 5
 
         a = list(range(3))
-        raises(TypeError, operator.irepeat)
-        raises(TypeError, operator.irepeat, a, None)
-        raises(TypeError, operator.irepeat, a, [])
-        raises(TypeError, operator.irepeat, a, X())
-        raises(TypeError, operator.irepeat, 6, 7)
-        assert operator.irepeat(a, 2) is a
+        raises(TypeError, operator.imul)
+        raises(TypeError, operator.imul, a, None)
+        raises(TypeError, operator.imul, a, [])
+        assert operator.imul(a, 2) is a
         assert a == [0, 1, 2, 0, 1, 2]
-        assert operator.irepeat(a, 1) is a
+        assert operator.imul(a, 1) is a
         assert a == [0, 1, 2, 0, 1, 2]
 
     def test_methodcaller(self):