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

IntoPyCallbackOutput<_> is not implimented for arrays of pyclass #2323

Closed
andyblarblar opened this issue Apr 23, 2022 · 3 comments · Fixed by #2326
Closed

IntoPyCallbackOutput<_> is not implimented for arrays of pyclass #2323

andyblarblar opened this issue Apr 23, 2022 · 3 comments · Fixed by #2326
Labels

Comments

@andyblarblar
Copy link

Bug Description

I'm attempting to use a pyclass annotated struct array as the member of another pyclass annotated struct. When I attempt to annotate that array feild with pyo3(get), it fails to compile. I'm building off of the current master (dea9eb7) as it's latest commit seems to cover this use case.

Steps to Reproduce

Minimal example:

#[pyclass]
#[derive(Copy, Clone)]
struct Foo {
    x: i32
}

#[pyclass]
struct Bar {
    #[pyo3(get)]
    arr: [Foo; 12]
}

Backtrace

error[E0277]: the trait bound `[Foo; 12]: IntoPyCallbackOutput<_>` is not satisfied
   --> src/ld06_driver.rs:21:1
    |
21  | #[pyclass]
    | ^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `[Foo; 12]`
    |
    = help: the following other types implement trait `IntoPyCallbackOutput<Target>`:
              <() as IntoPyCallbackOutput<()>>
              <() as IntoPyCallbackOutput<i32>>
              <*mut PyObject as IntoPyCallbackOutput<*mut PyObject>>
              <HashCallbackOutput as IntoPyCallbackOutput<isize>>
              <IterANextOutput<Py<PyAny>, Py<PyAny>> as IntoPyCallbackOutput<*mut PyObject>>
              <IterANextOutput<T, U> as IntoPyCallbackOutput<IterANextOutput<Py<PyAny>, Py<PyAny>>>>
              <IterNextOutput<Py<PyAny>, Py<PyAny>> as IntoPyCallbackOutput<*mut PyObject>>
              <IterNextOutput<T, U> as IntoPyCallbackOutput<IterNextOutput<Py<PyAny>, Py<PyAny>>>>
            and 7 others
note: required by a bound in `pyo3::callback::convert`
   --> /home/andy/.cargo/git/checkouts/pyo3-a22e69bc62b9f0fd/dea9eb7/src/callback.rs:182:8
    |
182 |     T: IntoPyCallbackOutput<U>,
    |        ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `pyo3::callback::convert`


### Your operating system and version

Ubuntu 20.04

### Your Python version (`python --version`)

Python 3.8

### Your Rust version (`rustc --version`)

rustc 1.60.0 (7737e0b5c 2022-04-04)

### Your PyO3 version

dea9eb7a master

### How did you install python? Did you use a virtualenv?

apt

### Additional Info

_No response_
@mejrs
Copy link
Member

mejrs commented Apr 23, 2022

You just need to add this implementation to make it work:

impl ToPyObject for Foo{
    fn to_object(&self, py: Python<'_>) -> PyObject{
        self.into_py(py)
    }
}

This error is actually really bad - I'd like to improve it.

@mejrs
Copy link
Member

mejrs commented Apr 23, 2022

Actually, I think I can make this work without requiring ToPyObject

@mejrs
Copy link
Member

mejrs commented Apr 23, 2022

I'm building off of the current master (dea9eb7) as it's latest commit seems to cover this use case.

That commit addresses the case of references to arrays, so it doesn't help here. However #2326 does :)

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

Successfully merging a pull request may close this issue.

2 participants