Skip to content

Commit 3218472

Browse files
authored
Revert "Make IntoPyObject for Bound & Borrowed more generic (#5831)"
This reverts commit ee66c21.
1 parent e9151b4 commit 3218472

4 files changed

Lines changed: 12 additions & 22 deletions

File tree

newsfragments/5831.added.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

newsfragments/5831.changed.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/conversion.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,55 +127,55 @@ pub(crate) mod private {
127127
}
128128
}
129129

130-
impl<'py, T: PyTypeCheck> IntoPyObject<'py> for Bound<'_, T> {
130+
impl<'py, T: PyTypeCheck> IntoPyObject<'py> for Bound<'py, T> {
131131
type Target = T;
132132
type Output = Bound<'py, Self::Target>;
133133
type Error = Infallible;
134134

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

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

143-
impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for &'a Bound<'_, T> {
143+
impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for &'a Bound<'py, T> {
144144
type Target = T;
145145
type Output = Borrowed<'a, 'py, Self::Target>;
146146
type Error = Infallible;
147147

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

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

156-
impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for Borrowed<'a, '_, T> {
156+
impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for Borrowed<'a, 'py, T> {
157157
type Target = T;
158158
type Output = Borrowed<'a, 'py, Self::Target>;
159159
type Error = Infallible;
160160

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

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

169-
impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for &Borrowed<'a, '_, T> {
169+
impl<'a, 'py, T: PyTypeCheck> IntoPyObject<'py> for &Borrowed<'a, 'py, T> {
170170
type Target = T;
171171
type Output = Borrowed<'a, 'py, Self::Target>;
172172
type Error = Infallible;
173173

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

177-
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
178-
Ok(self.as_unbound().bind_borrowed(py))
177+
fn into_pyobject(self, _py: Python<'py>) -> Result<Self::Output, Self::Error> {
178+
Ok(*self)
179179
}
180180
}
181181

src/instance.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,14 +1075,6 @@ impl<'a, 'py, T> Borrowed<'a, 'py, T> {
10751075
pub unsafe fn cast_unchecked<U>(self) -> Borrowed<'a, 'py, U> {
10761076
Borrowed(self.0, PhantomData, self.2)
10771077
}
1078-
1079-
/// Removes the connection for this `Borrowed<T>` from the [`Python<'py>`] token,
1080-
/// allowing it to cross thread boundaries, without transferring ownership.
1081-
#[inline]
1082-
pub fn as_unbound(&self) -> &'a Py<T> {
1083-
// Safety: NonNull<ffi::PyObject> is layout-compatible with Py<T>
1084-
unsafe { NonNull::from(&self.0).cast().as_ref() }
1085-
}
10861078
}
10871079

10881080
impl<'a, T: PyClass> Borrowed<'a, '_, T> {

0 commit comments

Comments
 (0)