PyO3 / PyO3/pyo3

PEP 688 buffer methods

Open
#3,148 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading PEP 688 and the existing getbuffer and releasebuffer support, then compare their ffi::Py_buffer handling with the proposed Python-level methods. The issue is done when PyO3 supports buffer and release_buffer while retaining a way to use full ffi::Py_buffer flexibility; the exact design remains open.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.