mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
PyTraceback Constructor (#5958)
This commit is contained in:
2
Lib/test/test_raise.py
vendored
2
Lib/test/test_raise.py
vendored
@@ -270,8 +270,6 @@ class TestTracebackType(unittest.TestCase):
|
||||
tb.tb_next = new_tb
|
||||
self.assertIs(tb.tb_next, new_tb)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_constructor(self):
|
||||
other_tb = get_tb()
|
||||
frame = sys._getframe()
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use rustpython_common::lock::PyMutex;
|
||||
|
||||
use super::PyType;
|
||||
use super::{PyType, PyTypeRef};
|
||||
use crate::{
|
||||
Context, Py, PyPayload, PyRef, class::PyClassImpl, frame::FrameRef, source::LineNumber,
|
||||
Context, Py, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, frame::FrameRef,
|
||||
source::LineNumber, types::Constructor,
|
||||
};
|
||||
|
||||
#[pyclass(module = false, name = "traceback", traverse)]
|
||||
@@ -25,7 +26,7 @@ impl PyPayload for PyTraceback {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass]
|
||||
#[pyclass(with(Constructor))]
|
||||
impl PyTraceback {
|
||||
pub const fn new(
|
||||
next: Option<PyRef<Self>>,
|
||||
@@ -67,6 +68,18 @@ impl PyTraceback {
|
||||
}
|
||||
}
|
||||
|
||||
impl Constructor for PyTraceback {
|
||||
type Args = (Option<PyRef<PyTraceback>>, FrameRef, u32, usize);
|
||||
|
||||
fn py_new(cls: PyTypeRef, args: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
let (next, frame, lasti, lineno) = args;
|
||||
let lineno = LineNumber::new(lineno)
|
||||
.ok_or_else(|| vm.new_value_error("lineno must be positive".to_owned()))?;
|
||||
let tb = PyTraceback::new(next, frame, lasti, lineno);
|
||||
tb.into_ref_with_type(vm, cls).map(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl PyTracebackRef {
|
||||
pub fn iter(&self) -> impl Iterator<Item = Self> {
|
||||
std::iter::successors(Some(self.clone()), |tb| tb.next.lock().clone())
|
||||
|
||||
Reference in New Issue
Block a user