rust-cpython icon indicating copy to clipboard operation
rust-cpython copied to clipboard

Documentation for kwargs in instance method

Open 197g opened this issue 5 years ago • 1 comments

As far as I've been able to determine one needs to specify *args for **kwargs to work in an instance method. The documentation for py_argparse indicates that this is a bug. It allows parameter to have either syntax but doesn't specify that one is required for the other to work. Python also allows it (e.g. def f(**kwargs): is a valid signature).

// Doesn't work :(
// [Error] no rules expected the token `{`
py_class!(class Example |py| {
    def _replace(&self, **kwargs) -> PyResult<NoArgs> {
        Ok(NoArgs)
    }
});
// Workaround that works :)
py_class!(class Example |py| {
    def _replace(&self, *args, **kwargs) -> PyResult<NoArgs> {
        Ok(NoArgs)
    }
});

If it significantly affects the complexity of the implementation then this restriction is fine and the workaround definitely works for my use case. Feel free to regard this as a pure documentation bug if you want.

197g avatar Jun 19 '20 13:06 197g

I hope it can be fixed. Having to manually implement the error response for receiving the wrong number of positional arguments from Python seems un-Rusty at best.

ssokolow avatar Jun 19 '20 13:06 ssokolow