From 912b9e4e5972e8fd20765fa7a1f9dee557f524ad Mon Sep 17 00:00:00 2001
From: Adam Reichold <adam.reichold@t-online.de>
Date: Mon, 1 May 2023 20:55:48 +0200
Subject: [PATCH] Extend lifetime of GIL token associated with PyRef(Mut).

---
 src/pycell.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/pycell.rs b/src/pycell.rs
index 0be39ac674d..dbd5fff9b9b 100644
--- a/src/pycell.rs
+++ b/src/pycell.rs
@@ -583,8 +583,8 @@ pub struct PyRef<'p, T: PyClass> {
 
 impl<'p, T: PyClass> PyRef<'p, T> {
     /// Returns a `Python` token that is bound to the lifetime of the `PyRef`.
-    pub fn py(&self) -> Python<'_> {
-        unsafe { Python::assume_gil_acquired() }
+    pub fn py(&self) -> Python<'p> {
+        self.inner.py()
     }
 }
 
@@ -706,8 +706,8 @@ pub struct PyRefMut<'p, T: PyClass<Frozen = False>> {
 
 impl<'p, T: PyClass<Frozen = False>> PyRefMut<'p, T> {
     /// Returns a `Python` token that is bound to the lifetime of the `PyRefMut`.
-    pub fn py(&self) -> Python<'_> {
-        unsafe { Python::assume_gil_acquired() }
+    pub fn py(&self) -> Python<'p> {
+        self.inner.py()
     }
 }