Conversation
- A trait `PyCapsuleType` to give the capsule name for the type and encode that the type is pycapsule-safe
- Two wrapper types `PyCapsuleValue` and `PyCapsuleValueRef` that implement `FromPyObject` and `IntoTypeObject` wrapping respectively T and &T
Example of API goal:
```rust
#[pyfunction]
fn add_one(foo: PyCapsuleValueRef<'_, Foo>) -> PyCapsuleValue<Foo> {
PyCapsuleValue(Foo { val: foo.val })
}
```
Contributor
|
Just out of curiosity, why would someone want this? My understanding is that the PyCapsule API is there to serve use-cases like NumPy's C API where someone wants to expose a C API for a Python library that must be imported before it can be usable from C. Are you trying to enable a similar pattern with PyO3 or something else entirely? |
Contributor
Author
|
@ngoldbaum Yes! This is this kind of usecases. For example datafusion Python bindings relies a lot on capsule for extensibilities and method definition like: pub fn __datafusion_table_provider__<'py>(
&self,
py: Python<'py>,
session: Bound<PyAny>,
) -> PyResult<Bound<'py, PyCapsule>> {can become pub fn __datafusion_table_provider__(
&self,
session: PyCapsuleValueRef<'_, FFI_LogicalExtensionCodec>,
) -> PyResult<PyCapsuleValue<FFI_TableProvider>> { |
Contributor
|
Ah, TIL there's an Arrow PyCapsule interface: https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PyCapsuleTypeto give the capsule name for the type and encode that the type is pycapsule-safePyCapsuleValueandPyCapsuleValueRefthat implementFromPyObjectandIntoTypeObjectwrapping respectively T and &TExample of API goal: