Python operator 模块,invert() 实例源码

我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用operator.invert()

项目:texta    作者:texta-tk    | 项目源码 | 文件源码
def _build_logical_expression(self, grammar, terminal_component_names):
        terminal_component_symbols = eval("symbols('%s')"%(' '.join(terminal_component_names)))
        if isinstance(terminal_component_symbols, Symbol):
            terminal_component_symbols = [terminal_component_symbols]
        name_to_symbol = {terminal_component_names[i]:symbol for i, symbol in enumerate(terminal_component_symbols)}
        terminal_component_names = set(terminal_component_names)

        op_to_symbolic_operation = {'not':operator.invert, 'concat':operator.and_, 'gap':operator.and_, 'union':operator.or_, 'intersect':operator.and_}

        def logical_expression_builder(component):
            if component['id'] in terminal_component_names:
                return name_to_symbol[component['id']]
            else:
                children = component['components']
                return reduce(op_to_symbolic_operation[component['operation']],[logical_expression_builder(child) for child in children])

        return simplify(logical_expression_builder(grammar))
项目:pudzu    作者:Udzu    | 项目源码 | 文件源码
def number_of_args(fn):
    """Return the number of positional arguments for a function, or None if the number is variable.
    Looks inside any decorated functions."""
    try:
        if hasattr(fn, '__wrapped__'):
            return number_of_args(fn.__wrapped__)
        if any(p.kind == p.VAR_POSITIONAL for p in signature(fn).parameters.values()):
            return None
        else:
            return sum(p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD) for p in signature(fn).parameters.values())
    except ValueError:
        # signatures don't work for built-in operators, so check for a few explicitly
        UNARY_OPS = [len, op.not_, op.truth, op.abs, op.index, op.inv, op.invert, op.neg, op.pos]
        BINARY_OPS = [op.lt, op.le, op.gt, op.ge, op.eq, op.ne, op.is_, op.is_not, op.add, op.and_, op.floordiv, op.lshift, op.mod, op.mul, op.or_, op.pow, op.rshift, op.sub, op.truediv, op.xor, op.concat, op.contains, op.countOf, op.delitem, op.getitem, op.indexOf]
        TERNARY_OPS = [op.setitem]
        if fn in UNARY_OPS:
            return 1
        elif fn in BINARY_OPS:
            return 2
        elif fn in TERNARY_OPS:
            return 3
        else:
            raise NotImplementedError("Bult-in operator {} not supported".format(fn))
项目:myhdlpeek    作者:xesscorp    | 项目源码 | 文件源码
def __invert__(self):
        return self.apply_op1(operator.invert)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_invert_array(self):
        self.check_array_op(operator.invert)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_invert_zerodim(self):
        self.check_zerodim_op(operator.invert)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_invert(self):
        self.assertRaises(TypeError, operator.invert)
        self.assertRaises(TypeError, operator.invert, None)
        self.assertEqual(operator.inv(4), -5)
项目:Vector-Tiles-Reader-QGIS-Plugin    作者:geometalab    | 项目源码 | 文件源码
def __invert__(self):
    return NonStandardInteger(operator.invert(self.val))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_invert(self):
        self.assertRaises(TypeError, operator.invert)
        self.assertRaises(TypeError, operator.invert, None)
        self.assertTrue(operator.inv(4) == -5)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_invert(self):
        self.assertRaises(TypeError, operator.invert)
        self.assertRaises(TypeError, operator.invert, None)
        self.assertTrue(operator.inv(4) == -5)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_invert_array(self):
        self.check_array_op(operator.invert)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_invert_zerodim(self):
        self.check_zerodim_op(operator.invert)
项目:lsdc    作者:febert    | 项目源码 | 文件源码
def setUp(self):
    super(LogicalNotTest, self).setUp()
    self.ops = [
        ('logical_not', operator.invert, tf.logical_not, core.logical_not),
    ]
    self.test_lt = self.original_lt < 10
项目:coremltools    作者:apple    | 项目源码 | 文件源码
def __invert__(self):
    return NonStandardInteger(operator.invert(self.val))
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_invert(self):
        self.assertRaises(TypeError, operator.invert)
        self.assertRaises(TypeError, operator.invert, None)
        self.assertEqual(operator.inv(4), -5)
项目:hyper-engine    作者:maxim5    | 项目源码 | 文件源码
def __invert__(self):  return _op1(self, operator.invert)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_invert(self):
        self.assertRaises(TypeError, operator.invert)
        self.assertRaises(TypeError, operator.invert, None)
        self.assertTrue(operator.inv(4) == -5)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_invert(self):
        self.assertRaises(TypeError, operator.invert)
        self.assertRaises(TypeError, operator.invert, None)
        self.assertTrue(operator.inv(4) == -5)
项目:bytecode    作者:vstinner    | 项目源码 | 文件源码
def eval_UNARY_INVERT(self, instr):
        return self.unaryop(operator.invert, instr)
项目:go2mapillary    作者:enricofer    | 项目源码 | 文件源码
def __invert__(self):
    return NonStandardInteger(operator.invert(self.val))
项目:DeepLearning_VirtualReality_BigData_Project    作者:rashmitripathi    | 项目源码 | 文件源码
def setUp(self):
    super(LogicalNotTest, self).setUp()
    self.ops = [('logical_not', operator.invert, math_ops.logical_not,
                 core.logical_not),]
    self.test_lt = self.original_lt < 10