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

Unable to specify keyword-only arguments #1025

Closed
sunjay opened this issue Jul 6, 2020 · 6 comments · Fixed by #1209
Closed

Unable to specify keyword-only arguments #1025

sunjay opened this issue Jul 6, 2020 · 6 comments · Fixed by #1209

Comments

@sunjay
Copy link

sunjay commented Jul 6, 2020

🌍 Environment

  • Your operating system and version: Linux Mint 19.3
  • Your python version: Python 3.6.9
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: Using apt, no virtualenv
  • Your Rust version (rustc --version): rustc 1.44.1 (c7087fe00 2020-06-17)
  • Your PyO3 version: 0.11.1
  • Have you tried using latest PyO3 master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: yes

💥 Reproducing

Minimal reproduction:

#[pyfunction("*", a, b)]
fn sum(a: usize, b: usize) -> usize {
    a + b
}

This is valid and should be allowed. The arguments a and b are keyword-only, which means that this function needs to be called as sum(a=3, b=3).

Compiling this produces the error:

error: Positional argument or varargs(*) is not allowed after *
   --> src/lib.rs:3:19
    |
  3 | #[pyfunction("*", a, b)]
    |                   ^

error: aborting due to previous error

The equivalent Python code that works with Python 3:

def sum(*, a, b):
    return a + b

I think this is related to #790 and the subsequent changes made in #792.

@kngwyu
Copy link
Member

kngwyu commented Jul 6, 2020

Thank you for reporting!
It looks like I misunderstood this syntax 😓

@dvermd
Copy link
Contributor

dvermd commented Sep 27, 2020

If nobody's already taken this one, I'll give it a try

@davidhewitt
Copy link
Member

@dvermd please do! I'm happy to answer any questions and review your PR 👍

@dvermd
Copy link
Contributor

dvermd commented Sep 27, 2020

I'm thinking of replacing the booleans has_kw, has_varargs and has_kwargs in pyfunctions.rs by an enum or a state machine. This part is defining the function.
Is there also any code validating the parameters when calling a function ?

@davidhewitt
Copy link
Member

Sounds good

Is there also any code validating the parameters when calling a function ?

I think you're looking for parse_fn_args

@kngwyu
Copy link
Member

kngwyu commented Sep 27, 2020

Thanks.

I'm thinking of replacing the booleans has_kw, has_varargs and has_kwargs in pyfunctions.rs by an enum or a state machine. This part is defining the function.

The current code is already a state machine and I don't think abstracting it more is so meaningful.
What we need is just to treat arguments after * as keyword-only arguments in add_work

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

Successfully merging a pull request may close this issue.

4 participants