Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion newsfragments/5831.added.md

This file was deleted.

1 change: 0 additions & 1 deletion newsfragments/5831.changed.md

This file was deleted.

24 changes: 12 additions & 12 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,55 +127,55 @@ pub(crate) mod private {
}
}

impl<'py, T: PyTypeCheck> IntoPyObject<'py> for Bound<'_, T> {
impl<'py, T: PyTypeCheck> IntoPyObject<'py> for Bound<'py, T> {
type Target = T;
type Output = Bound<'py, Self::Target>;
type Error = Infallible;

#[cfg(feature = "experimental-inspect")]
const OUTPUT_TYPE: PyStaticExpr = T::TYPE_HINT;

fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
Ok(self.unbind().into_bound(py))
fn into_pyobject(self, _py: Python<'py>) -> Result<Self::Output, Self::Error> {
Ok(self)
}
}

impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for &'a Bound<'_, T> {
impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for &'a Bound<'py, T> {
type Target = T;
type Output = Borrowed<'a, 'py, Self::Target>;
type Error = Infallible;

#[cfg(feature = "experimental-inspect")]
const OUTPUT_TYPE: PyStaticExpr = T::TYPE_HINT;

fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
Ok(self.as_unbound().bind_borrowed(py))
fn into_pyobject(self, _py: Python<'py>) -> Result<Self::Output, Self::Error> {
Ok(self.as_borrowed())
}
}

impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for Borrowed<'a, '_, T> {
impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for Borrowed<'a, 'py, T> {
type Target = T;
type Output = Borrowed<'a, 'py, Self::Target>;
type Error = Infallible;

#[cfg(feature = "experimental-inspect")]
const OUTPUT_TYPE: PyStaticExpr = T::TYPE_HINT;

fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
Ok(self.as_unbound().bind_borrowed(py))
fn into_pyobject(self, _py: Python<'py>) -> Result<Self::Output, Self::Error> {
Ok(self)
}
}

impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for &Borrowed<'a, '_, T> {
impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for &Borrowed<'a, 'py, T> {
type Target = T;
type Output = Borrowed<'a, 'py, Self::Target>;
type Error = Infallible;

#[cfg(feature = "experimental-inspect")]
const OUTPUT_TYPE: PyStaticExpr = T::TYPE_HINT;

fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
Ok(self.as_unbound().bind_borrowed(py))
fn into_pyobject(self, _py: Python<'py>) -> Result<Self::Output, Self::Error> {
Ok(*self)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could keep the other cases except this one I think.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about this further, and it occurred to me that one place where the lifetimes differ in the future might be subinterpreters.

Maybe given that were not entirely sure how that will play out, better to play cautious and not relax these implementations until a user asks for it?

}
}

Expand Down
8 changes: 0 additions & 8 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,14 +1075,6 @@ impl<'a, 'py, T> Borrowed<'a, 'py, T> {
pub unsafe fn cast_unchecked<U>(self) -> Borrowed<'a, 'py, U> {
Borrowed(self.0, PhantomData, self.2)
}

/// Removes the connection for this `Borrowed<T>` from the [`Python<'py>`] token,
/// allowing it to cross thread boundaries, without transferring ownership.
#[inline]
pub fn as_unbound(&self) -> &'a Py<T> {
// Safety: NonNull<ffi::PyObject> is layout-compatible with Py<T>
unsafe { NonNull::from(&self.0).cast().as_ref() }
}
}

impl<'a, T: PyClass> Borrowed<'a, '_, T> {
Expand Down
Loading