◐ Shell
clean mode source ↗

Update `traceback.tb_next` to be writable. by tgsong827 · Pull Request #4087 · RustPython/RustPython

@@ -1,10 +1,12 @@ use rustpython_common::lock::PyMutex;
use super::PyType; use crate::{class::PyClassImpl, frame::FrameRef, Context, Py, PyPayload, PyRef, VirtualMachine};
#[pyclass(module = false, name = "traceback")] #[derive(Debug)] pub struct PyTraceback { pub next: Option<PyTracebackRef>, // TODO: Make mutable pub next: PyMutex<Option<PyTracebackRef>>, pub frame: FrameRef, pub lasti: u32, pub lineno: usize, Expand All @@ -22,7 +24,7 @@ impl PyPayload for PyTraceback { impl PyTraceback { pub fn new(next: Option<PyRef<Self>>, frame: FrameRef, lasti: u32, lineno: usize) -> Self { PyTraceback { next, next: PyMutex::new(next), frame, lasti, lineno, Expand All @@ -46,13 +48,18 @@ impl PyTraceback {
#[pyproperty] fn tb_next(&self) -> Option<PyRef<Self>> { self.next.as_ref().cloned() self.next.lock().as_ref().cloned() }
#[pyproperty(setter)] fn set_tb_next(&self, value: Option<PyRef<Self>>) { *self.next.lock() = value; } }
impl PyTracebackRef { pub fn iter(&self) -> impl Iterator<Item = PyTracebackRef> { std::iter::successors(Some(self.clone()), |tb| tb.next.clone()) std::iter::successors(Some(self.clone()), |tb| tb.next.lock().clone()) } }
Expand Down