Skip to content

PEP 688 buffer methods #3148

@davidhewitt

Description

@davidhewitt

PEP 688 defines new methods __buffer__ and __release_buffer__ with signatures as follows:

    def __buffer__(self, flags: int, /) -> memoryview: ...
    def __release_buffer__(self, buffer: memoryview, /) -> None: ...

At the moment we have __getbuffer__ and __releasebuffer__ which have slightly different signatures, because they deal in the ffi::Py_buffer type.

It would be nice if we could support the PEP 688 methods, ideally with a way to use the full ffi::Py_buffer flexibility when users need it.

One option could be that we only support the PEP 688 way as first-class, and then allow the user to annotate a method with #[pyo3(unsafe_type_slot = bf_getbuffer)] to directly insert a method into the buffer slot (this could be generally useful for all type slots without requiring us to write any special machinery).

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