11use rustpython_common:: lock:: PyMutex ;
22
3- use super :: PyType ;
3+ use super :: { PyType , PyTypeRef } ;
44use 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 ) ) ]
2930impl 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+
7083impl 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