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

Documentation for kwargs in instance method #236

Open
HeroicKatora opened this issue Jun 19, 2020 · 1 comment
Open

Documentation for kwargs in instance method #236

HeroicKatora opened this issue Jun 19, 2020 · 1 comment

Comments

@HeroicKatora
Copy link

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.

@ssokolow
Copy link

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.

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