def python_signature_complete(prefix, line, end, ctx, filter_func): """Completes a python function (or other callable) call by completing argument and keyword argument names. """ front = line[:end] if xt.is_balanced(front, '(', ')'): return set() funcname = xt.subexpr_before_unbalanced(front, '(', ')') val, _ctx = _safe_eval(funcname, ctx) if val is None: return set() try: sig = inspect.signature(val) except ValueError: return set() args = {p + '=' for p in sig.parameters if filter_func(p, prefix)} return args
def python_signature_complete(prefix, line, end, ctx, filter_func): """Completes a python function (or other callable) call by completing argument and keyword argument names. """ front = line[:end] if xt.is_balanced(front, '(', ')'): return set() funcname = xt.subexpr_before_unbalanced(front, '(', ')') val, _ctx = _safe_eval(funcname, ctx) if val is None and _ctx is None: return set() try: sig = inspect.signature(val) except ValueError: return set() args = {p + '=' for p in sig.parameters if filter_func(p, prefix)} return args
def test_subexpr_before_unbalanced_parens(inp, exp): obs = subexpr_before_unbalanced(inp, "(", ")") assert exp == obs
def test_subexpr_before_unbalanced_parens(inp, exp): obs = subexpr_before_unbalanced(inp, '(', ')') assert exp == obs