-
Notifications
You must be signed in to change notification settings - Fork 769
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
migrate FromPyObject
for Bound
and Py
to new APIs
#3776
Conversation
66d974a
to
89b08c1
Compare
CodSpeed Performance ReportMerging #3776 will improve performances by 11.44%Comparing Summary
Benchmarks breakdown
|
I'll push to add some test coverage to this. |
89b08c1
to
e83ee04
Compare
Ok, pushed. |
e83ee04
to
a60c182
Compare
Updated this just to add a note to the migration guide about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration looks correct to me (from purely looking at the implementation, i dont have the overview (yet) to see, how this ties into the trait and macro system).
I agree that &Bound
should be usable in function and method argument position. I cant see a way of changing FromPyObject
in a backwards compatible way, which would allow this implementation, either. So using PyFunctionArgument
here seems reasonable to me.
PyFunctionArgument
will need the same treatment as FromPyObject
, as in introducing extract_bound
, but that can also be a separate PR I think.
Thanks! Let's merge this then, and I'll get on with splitting out the rest of the PRs which depend on it.
As |
This PR is two commits which refine
FromPyObject
for our smart pointers:FromPyObject
for bothBound<T>
andPy<T>
to just beT: PyTypeCheck
, while migrating toextract_bound
at the same time. This is loosely a follow-up from Addextract_bound
method to FromPyObject #3706PyFunctionArgument for &Bound<T>
, allowing#[pyfunction]
and#[pymethods]
to accept&Bound<T>
. I think it's desirable to allow this, and it's not possible to implementFromPyObject for &Bound<T>
because while the backwards-compatible definition ofFromPyObject
for the GIL-ref API can't express that lifetime of the reference correctly. In the future we could potentially haveFromPyObject<'a, 'py> for &'a Bound<'py, T>
if we introduce a second lifetime toFromPyObject
.(I think that second lifetime is necessary if we also wanted
FromPyObject<'a, 'py> for Borrowed<'a, 'py, T>
too, but I'm less motivated for that and similarly would like to skip addingPyFunctionArgument
forBorrowed<T>
unless users are reporting it as a useful addition.)