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

Cannot return PyBytes / PyList? #1549

Closed
vedantroy opened this issue Apr 7, 2021 · 3 comments
Closed

Cannot return PyBytes / PyList? #1549

vedantroy opened this issue Apr 7, 2021 · 3 comments

Comments

@vedantroy
Copy link

vedantroy commented Apr 7, 2021

I have the following:

    pub fn apply_local_change(&mut self, change: &PyAny) -> PyResult<(Py<PyAny>, PyBytes)> {
       // function implementation ...
        let bytes = *PyBytes::new(py, change.raw_bytes());
        Ok((pythonize(py, &patch)?, bytes))
    }

However, I get an error saying "the trait IntoPyCallbackOutput<_> is not implemented for Result<(pyo3::Py<PyAny>, PyBytes), PyErr>". Is there any reason this trait would not be implemented for PyBytes?

I can solve the problem by returning a Vec<u8>, but that seems less Pythonic.

Update: This seems to apply for all Py... types, i.e, I can't return a Pylist either.

@vedantroy vedantroy changed the title Cannot return PyBytes? Cannot return PyBytes / PyList? Apr 7, 2021
@ravenexp
Copy link
Contributor

ravenexp commented Apr 8, 2021

I think this is because you are trying to return a Rust tuple. Maybe you could try returning a PyTuple object instead.

@davidhewitt
Copy link
Member

Sorry for my slow response! The return type needs to be PyResult<(Py<PyAny>, &PyBytes)> or PyResult<(Py<PyAny>, Py<PyBytes>)>.

(Plain PyBytes isn't meaningful with PyO3 - it needs to be wrapped as a pointer either as &PyBytes or Py<PyBytes>. This is likely going to improve eventually with #1308.)

@davidhewitt
Copy link
Member

Will close this as it's been a stale discussion and we'll be marking a lot of documentation changes in #3382

@davidhewitt davidhewitt closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants