Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call a function with named arguments #22

Open
pvcnt opened this issue Nov 25, 2024 · 1 comment
Open

Cannot call a function with named arguments #22

pvcnt opened this issue Nov 25, 2024 · 1 comment

Comments

@pvcnt
Copy link
Contributor

pvcnt commented Nov 25, 2024

It looks like it is impossible to call a function with named arguments. While g(1) works well, g(x=1) results in an error.

How to reproduce

Given the following snippet:

import starlark as sl

glb = sl.Globals.standard()
mod = sl.Module()


def g(x):
    print(f"g called with {x}")
    return 2 * x


mod.add_callable("g", g)

ast = sl.parse("a.star", "g(x=1)")


def load(name):
    raise FileNotFoundError(name)


sl.eval(mod, ast, glb, sl.FileLoader(load))

I obtain the following error:

error: Found `x` extra named parameter(s) for call to function
@inducer
Copy link
Owner

inducer commented Nov 25, 2024

Yep, not currently implemented:

starlark-pyo3/src/lib.rs

Lines 622 to 641 in 00f5fe7

impl<'v> StarlarkValue<'v> for PythonCallableValue {
fn invoke(
&self,
_me: Value<'v>,
args: &Arguments<'v, '_>,
eval: &mut starlark::eval::Evaluator<'v, '_>,
) -> anyhow::Result<Value<'v>> {
Python::with_gil(|py| -> anyhow::Result<Value<'v>> {
args.no_named_args()?;
let py_args: Vec<PyObject> = (args
.positions(eval.heap())?
.map(|v| -> PyResult<PyObject> { value_to_pyobject(v) }))
.collect::<PyResult<Vec<PyObject>>>()?;
convert_to_anyhow(pyobject_to_value(
self.callable.call1(py, PyTuple::new_bound(py, py_args))?,
eval.heap(),
))
})
}
}

Help welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants