Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def pipe_with_meta(f, *args, **kwargs):
return create_pipe_call(f, MetaArg("_"), *args, **kwargs)
def wrapper(__data, *args, **kwargs):
return create_pipe_call(f, MetaArg("_"), *args, **kwargs)
def wrapper(*args, **kwargs):
return create_pipe_call(f, MetaArg("_"), *args, **kwargs)
return f
def simple_varname(call):
if isinstance(call, str):
return call
# check for expr like _.some_var or _["some_var"]
if (isinstance(call, Call)
and call.func in {"__getitem__", "__getattr__"}
and isinstance(call.args[0], MetaArg)
and isinstance(call.args[1], str)
):
# return variable name
return call.args[1]
return None
def format(self, call, pad = 0):
"""Return a Symbolic or Call back as a nice tree, with boxes for nodes."""
fmt_block = "█─"
fmt_pipe = "├─"
# TODO: why are some nodes still symbolic?
if isinstance(call, Symbolic):
return self.format(strip_symbolic(call))
if isinstance(call, MetaArg):
return "_"
if isinstance(call, Call):
call_str = fmt_block + ALL_OPS.get(call.func, repr(call.func))
args_str = [self.format(arg) for arg in call.args]
# format keyword args, making sure "└─ = █─" aligns box's children
kwargs_str = []
for k, v in call.kwargs.items():
kwargs_str.append(
k + " = " + self.format(v, pad = len(k) + 3)
)
all_args = [*args_str, *kwargs_str]
padded = []
def str_to_getitem_call(x):
return Call("__getitem__", MetaArg("_"), x)
def replace_next(node):
# swap in first replacement for meta arg (when possible)
if isinstance(node, MetaArg):
return next(replacements)
# otherwise, recurse into node
args, kwargs = node.map_subcalls(replace_next)
# return a copy of node
return node.__class__(node.func, *args, **kwargs)