port PyObject::downcast to Bound API#3856
Conversation
CodSpeed Performance ReportMerging #3856 will degrade performances by 15.63%Comparing Summary
Benchmarks breakdown
|
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks for picking this one up! Just one piece which I think we can tweak further.
| /// Compatibility API to convert the Bound variant `DowncastError` into the | ||
| /// gil-ref variant | ||
| pub(crate) fn from_downcast_err(DowncastError { from, to }: DowncastError<'a, 'a>) -> Self { | ||
| Self { | ||
| from: from.as_gil_ref(), | ||
| to, | ||
| } | ||
| } |
There was a problem hiding this comment.
Good idea, I also had some similar pieces in #3706 and maybe I can build on top of this API 👍
davidhewitt
left a comment
There was a problem hiding this comment.
downcast APIs, look good! I wonder about a different strategy for the cast_as APIs? (See comment.)
dcd2745 to
019288f
Compare
src/marker.rs
Outdated
| not(feature = "gil-refs"), | ||
| deprecated( | ||
| since = "0.21.0", | ||
| note = "`Python::checked_cast_as` will be replaced by `PyObject::downcast_bound` in a future PyO3 version" |
There was a problem hiding this comment.
Given the semantics of the "replacement" is slightly different, maybe something like the following wording is more helpful to users:
| note = "`Python::checked_cast_as` will be replaced by `PyObject::downcast_bound` in a future PyO3 version" | |
| note = "part of the deprecated GIL Ref API, to migrate use `obj.downcast_bound::<T>(py)` instead of `py.cast_as::<T>(obj)`" |
What do you think of this (and similar below)?
Part of #3684
This ports the
PyObject::downcast(_unchecked)methods to theBoundAPI.Edit:
I also added includedWe decided to deprecate these in favor of thePython::(checked_)cast_ashere.PyObjectmethods.