Avoid returning PyObject
and add wrapper types for arro3 export
#269
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.
Avoid returning
PyObject
, and preferBound<'py, PyAny>
instead.For a long time I didn't really understand the difference between
PyObject
andBound<'py, PyAny>
. But recently I've learned that the former is like a "bare"PyAny
while the latter isPyAny
with an associatedpy: Python
token. That means you can do Python operations without needing to separately acquire the GIL.It's preferable to return
Bound
, because that's what calls into Python return. It works nicer with theIntoPyObject
trait. And it's easy to call.unbind()
to get aPy<PyAny>
(aPyObject
).This also adds wrapper types to simplify export to arro3.
Now that we're using pyo3 0.23, there's a new IntoPyObject trait. This is a lot nicer than the previous
IntoPy
trait, because it allows for fallible conversions. So we can callto_arro3()
from within theIntoPyObject
trait impl. And e.g. ifarro3.core
isn't available, it'll correctly error.These wrapper types also nudge people toward the right choice: to dynamically pass data to the user's runtime instance of
arro3.core
.