Skip to content

Commit 16aaad7

Browse files
authored
PyTraceback Constructor (#5958)
1 parent 52d4632 commit 16aaad7

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Lib/test/test_raise.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,6 @@ def test_attrs(self):
270270
tb.tb_next = new_tb
271271
self.assertIs(tb.tb_next, new_tb)
272272

273-
# TODO: RUSTPYTHON
274-
@unittest.expectedFailure
275273
def test_constructor(self):
276274
other_tb = get_tb()
277275
frame = sys._getframe()

vm/src/builtins/traceback.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use rustpython_common::lock::PyMutex;
22

3-
use super::PyType;
3+
use super::{PyType, PyTypeRef};
44
use crate::{
5-
Context, Py, PyPayload, PyRef, class::PyClassImpl, frame::FrameRef, source::LineNumber,
5+
Context, Py, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, frame::FrameRef,
6+
source::LineNumber, types::Constructor,
67
};
78

89
#[pyclass(module = false, name = "traceback", traverse)]
@@ -25,7 +26,7 @@ impl PyPayload for PyTraceback {
2526
}
2627
}
2728

28-
#[pyclass]
29+
#[pyclass(with(Constructor))]
2930
impl PyTraceback {
3031
pub const fn new(
3132
next: Option<PyRef<Self>>,
@@ -67,6 +68,18 @@ impl PyTraceback {
6768
}
6869
}
6970

71+
impl Constructor for PyTraceback {
72+
type Args = (Option<PyRef<PyTraceback>>, FrameRef, u32, usize);
73+
74+
fn py_new(cls: PyTypeRef, args: Self::Args, vm: &VirtualMachine) -> PyResult {
75+
let (next, frame, lasti, lineno) = args;
76+
let lineno = LineNumber::new(lineno)
77+
.ok_or_else(|| vm.new_value_error("lineno must be positive".to_owned()))?;
78+
let tb = PyTraceback::new(next, frame, lasti, lineno);
79+
tb.into_ref_with_type(vm, cls).map(Into::into)
80+
}
81+
}
82+
7083
impl PyTracebackRef {
7184
pub fn iter(&self) -> impl Iterator<Item = Self> {
7285
std::iter::successors(Some(self.clone()), |tb| tb.next.lock().clone())

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy