diff --git a/src/instance.rs b/src/instance.rs index 4703dd12a94..cc1ae684e44 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -1329,8 +1329,11 @@ impl Py { /// # } /// ``` #[inline] - pub fn clone_ref(&self, py: Python<'_>) -> Py { - unsafe { Py::from_borrowed_ptr(py, self.0.as_ptr()) } + pub fn clone_ref(&self, _py: Python<'_>) -> Py { + unsafe { + ffi::Py_INCREF(self.as_ptr()); + Self::from_non_null(self.0) + } } /// Drops `self` and immediately decreases its reference count.