1
1
use rustpython_common:: lock:: PyMutex ;
2
2
3
- use super :: PyType ;
3
+ use super :: { PyType , PyTypeRef } ;
4
4
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 ,
6
7
} ;
7
8
8
9
#[ pyclass( module = false , name = "traceback" , traverse) ]
@@ -25,7 +26,7 @@ impl PyPayload for PyTraceback {
25
26
}
26
27
}
27
28
28
- #[ pyclass]
29
+ #[ pyclass( with ( Constructor ) ) ]
29
30
impl PyTraceback {
30
31
pub const fn new (
31
32
next : Option < PyRef < Self > > ,
@@ -67,6 +68,18 @@ impl PyTraceback {
67
68
}
68
69
}
69
70
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
+
70
83
impl PyTracebackRef {
71
84
pub fn iter ( & self ) -> impl Iterator < Item = Self > {
72
85
std:: iter:: successors ( Some ( self . clone ( ) ) , |tb| tb. next . lock ( ) . clone ( ) )
0 commit comments