示例#1
0
 def test_index(self):
     import operator
     assert operator.index(42) == 42
     assert operator.__index__(42) == 42
     exc = raises(TypeError, operator.index, "abc")
     assert str(
         exc.value) == "'str' object cannot be interpreted as an index"
示例#2
0
 def test_index(self):
     import operator
     assert operator.index(42) == 42
     assert operator.__index__(42) == 42
     raises(TypeError, operator.index, "abc")
     exc = raises(TypeError, operator.index, "abc")
     assert str(exc.value) == "'str' object cannot be interpreted as an integer"
示例#3
0
    def __getitem__(sf, i, /):
        def i2v(i, /):
            check_type_is(int, i)
            v = sf.__s[i]
            return sf.__cfg.to_view(v)

        t = type(i)
        if t is int or hasattr(t, '__index__'):
            i = operator.__index__(i)
            v = i2v(i)
            return v

        if t is slice:
            slice_ = i
            rng = fix_slice_by_len_of_(range, sf, slice_)
            #check may int!!!!
            slice_ = range2triple_(slice, rng)
            seq = sf.__s[slice_]
            return sf.from_sequence(seq)
        if t is tuple: raise TypeError
        raise TypeError(i)  #must be int/__index__, or slice
示例#4
0
 def __index__(self):
     """operator.index(self)"""
     return __index__(get_wrapped_object(self))
示例#5
0
 def update_event(self, inp=-1):
     self.set_output_val(0, operator.__index__(self.input(0)))
示例#6
0
文件: operator.py 项目: kanales/spycy
neg = spice(lambda x: operator.neg(x), name='neg', doc=operator.neg.__doc__)
__neg__ = spice(lambda x: operator.__neg__(x),
                name='__neg__',
                doc=operator.neg.__doc__)

not_ = spice(lambda x: operator.not_(x),
             name='not_',
             doc=operator.not_.__doc__)
__not__ = spice(lambda x: operator.__not__(x),
                name='__not__',
                doc=operator.not_.__doc__)

index = spice(lambda x: operator.index(x),
              name='index',
              doc=operator.index.__doc__)
__index__ = spice(lambda x: operator.__index__(x),
                  name='__index__',
                  doc=operator.index.__doc__)

itemgetter = spice(lambda x: operator.itemgetter(x),
                   name='itemgetter',
                   doc=operator.itemgetter.__doc__)
methodcaller = spice(lambda x: operator.methodcaller(x),
                     name='methodcaller',
                     doc=operator.methodcaller.__doc__)
attrgetter = spice(lambda x: operator.attrgetter(x),
                   name='attrgetter',
                   doc=operator.attrgetter.__doc__)

truth = spice(lambda x: operator.truth(x),
              name='truth',