migrate FromPyObject for Bound and Py to new APIs#3776
migrate FromPyObject for Bound and Py to new APIs#3776davidhewitt merged 2 commits intoPyO3:mainfrom
FromPyObject for Bound and Py to new APIs#3776Conversation
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 |
Icxolu
left a comment
There was a problem hiding this comment.
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
FromPyObjectfor our smart pointers:FromPyObjectfor bothBound<T>andPy<T>to just beT: PyTypeCheck, while migrating toextract_boundat the same time. This is loosely a follow-up from Addextract_boundmethod 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 ofFromPyObjectfor 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 addingPyFunctionArgumentforBorrowed<T>unless users are reporting it as a useful addition.)