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

Error when using _ as name for Bound argument in class method #59

Open
michaeljones opened this issue Aug 20, 2024 · 2 comments
Open

Error when using _ as name for Bound argument in class method #59

michaeljones opened this issue Aug 20, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@michaeljones
Copy link
Contributor

We are using _ as an argument name for the &Bound<'_, PyType> argument to a classmethod and I get the following error:

error: Expected typed argument
   --> project/src/lib.rs:107:9
    |
107 |         _: &Bound<'_, PyType>,
    |         ^

error: could not compile `nrf-probe-py` (lib) due to 1 previous error

If I rename it to bound or _bound then the error goes away. The argument isn't used in our current implementations.

Is that expected?

@termoshtt
Copy link
Collaborator

I guess it causes from #[pyfunction] rather than #[gen_stub_pyfunction].

#[pyfunction]
fn test_empty(_: Bound<'_, PyType>) {
    println!("test_empty");
}

will causes

error: wildcard argument names are not supported
  --> examples/pure/src/lib.rs:89:15
   |
89 | fn test_empty(_: Bound<'_, PyType>) {
   |               ^

@michaeljones
Copy link
Contributor Author

michaeljones commented Aug 20, 2024

I should have provided more of an example. It is failing on a impl method rather than a function and it is working without the pyo3-stub-gen annotation. The code looks like:

#[gen_stub_pymethods]
#[pymethods]
impl ObjectData {
    #[classmethod]
    fn from_map(
        _: &Bound<'_, PyType>,
        dict: HashMap<u32, Vec<u8>>,
    ) -> Result<Self, Error> {
       // ...
    }
}

It works without the #[gen_stub_pymethods] part. Does that seem meaningfully different to the pyfunction setup?

@termoshtt termoshtt added the bug Something isn't working label Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants