Esempio n. 1
0
def create_pipe_call(source, *args, **kwargs):
    first, *rest = args
    return Pipeable(
        Call("__call__", strip_symbolic(source), strip_symbolic(first),
             *(Lazy(strip_symbolic(x)) for x in rest),
             **{k: Lazy(strip_symbolic(v))
                for k, v in kwargs.items()}))
Esempio n. 2
0
    def generic_visit(self, node):
        children = node.get('children', tuple())

        func = node['name']
        args = tuple(map(self.visit, children))
        kwargs = {}

        return Call(func, *args, **kwargs)
Esempio n. 3
0
    def __call__(self, *args, **kwargs):
        call = Call('__call__',
                    BinaryOp('__getattr__', MetaArg("_"), self.name),
                    *args,
                    **kwargs
                    )

        return self.to_copy(name = call)
Esempio n. 4
0
def test_call_tree_local_dispatch_fail(f_dispatch_strict):
    ctl = CallTreeLocal({'f_a': lambda self: self}, dispatch_cls=object)

    call = Call("__call__", FuncArg(f_dispatch_strict), MetaArg('_'))

    # should be the default failure dispatch for object
    new_call = ctl.enter(call)
    with pytest.raises(TypeError):
        new_call('na')
Esempio n. 5
0
def call_factory(func, *args, **kwargs):
    method = flip_get(BINARY_OPS, func)
    if method:
        return BinaryOp(method, *args, **kwargs)

    method = flip_get(UNARY_OPS, func)
    if method:
        return UnaryOp(method, *args, **kwargs)

    return Call("__call__", NameArg(func), *args, **kwargs)
Esempio n. 6
0
def test_FuncArg_in_call():
    call = Call('__call__', FuncArg(lambda x, y: x + y), 1, y=2)

    assert call(None) == 3
Esempio n. 7
0
def test_call_tree_local_dispatch_cls_subclass(f_dispatch):
    ctl = CallTreeLocal({'f_a': lambda self: self}, dispatch_cls=SomeClass)

    call = Call("__call__", FuncArg(f_dispatch), MetaArg('_'))
    new_call = ctl.enter(call)
    assert new_call('na') == 'some class'
Esempio n. 8
0
def test_call_tree_local_dispatch_cls_object(f_dispatch):
    ctl = CallTreeLocal({'f_a': lambda self: self}, dispatch_cls=object)

    call = Call("__call__", FuncArg(f_dispatch), MetaArg('_'))
    new_call = ctl.enter(call)
    assert new_call('na') == 'default'
Esempio n. 9
0
    sym = eval(expr, {"_": _})
    index_op, slice_call = strip_symbolic(sym).args

    res = slice_call(data)
    assert res == target


# Node copying ================================================================

from siuba.siu import Call, BinaryOp, SliceOp, MetaArg, FuncArg, DictCall


# Call
@pytest.mark.parametrize('node', [
    Call("__call__", lambda x, y=2: x + y, 1, y=2),
    BinaryOp("__add__", 1, 2),
    SliceOp("__siu_slice__", slice(0, 1)),
    SliceOp("__siu_slice__", (slice(0, 1), slice(2, 3))),
    MetaArg("_"),
    FuncArg("__custom_func__", lambda x: x),
    FuncArg(lambda x: x),
    DictCall("__call__", dict, {
        'a': 1,
        'b': 2
    })
])
def test_node_copy(node):
    copy = node.copy()
    assert isinstance(copy, node.__class__)
    assert copy is not node
Esempio n. 10
0
    def visit_TerminalNodeImpl(self, node):
        if self.show_terminal:
            return Call(node['name'], node['text'])

        return node['text']