(self)
| 1927 | /// * If **owned** → reconstructs `PyObjectRef` from the raw pointer, forgets self. |
| 1928 | #[inline(always)] |
| 1929 | pub fn to_pyobj(self) -> PyObjectRef { |
| 1930 | let obj = if self.is_borrowed() { |
| 1931 | self.as_object().to_owned() // inc refcount |
| 1932 | } else { |
| 1933 | let ptr = unsafe { NonNull::new_unchecked(self.bits.get() as *mut PyObject) }; |
| 1934 | unsafe { PyObjectRef::from_raw(ptr) } |
| 1935 | }; |
| 1936 | core::mem::forget(self); // don't run Drop |
| 1937 | obj |
| 1938 | } |
| 1939 | |
| 1940 | /// Promote a borrowed ref to owned **in place** (increments refcount, |
| 1941 | /// clears the borrow tag). No-op if already owned. |
no test coverage detected