Skip to content

Documentation for kwargs in instance method #236

Open

Description

@197g

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.

Activity

  1. ssokolow commented on Jun 19, 2020

    @ssokolow

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions