@@ -11,7 +11,7 @@ use crate::{
1111 py_io:: { self , Write } ,
1212 stdlib:: sys,
1313 suggestion:: offer_suggestions,
14- types:: Callable ,
14+ types:: { Callable , Constructor , Initializer } ,
1515 AsObject , Context , Py , PyObjectRef , PyPayload , PyRef , PyResult , TryFromObject , VirtualMachine ,
1616} ;
1717use crossbeam_utils:: atomic:: AtomicCell ;
@@ -414,7 +414,7 @@ macro_rules! extend_exception {
414414 } ;
415415}
416416
417- #[ pyclass( flags( BASETYPE , HAS_DICT ) ) ]
417+ #[ pyclass( with ( Constructor , Initializer ) , flags( BASETYPE , HAS_DICT ) ) ]
418418impl PyBaseException {
419419 pub ( crate ) fn new ( args : Vec < PyObjectRef > , vm : & VirtualMachine ) -> PyBaseException {
420420 PyBaseException {
@@ -426,21 +426,6 @@ impl PyBaseException {
426426 }
427427 }
428428
429- #[ pyslot]
430- pub ( crate ) fn slot_new ( cls : PyTypeRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
431- PyBaseException :: new ( args. args , vm)
432- . into_ref_with_type ( vm, cls)
433- . map ( Into :: into)
434- }
435-
436- #[ pyslot]
437- #[ pymethod( magic) ]
438- pub ( crate ) fn init ( zelf : PyObjectRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult < ( ) > {
439- let zelf: PyRef < Self > = zelf. try_into_value ( vm) ?;
440- * zelf. args . write ( ) = PyTuple :: new_ref ( args. args , & vm. ctx ) ;
441- Ok ( ( ) )
442- }
443-
444429 pub fn get_arg ( & self , idx : usize ) -> Option < PyObjectRef > {
445430 self . args . read ( ) . get ( idx) . cloned ( )
446431 }
@@ -532,6 +517,25 @@ impl PyBaseException {
532517 }
533518}
534519
520+ impl Constructor for PyBaseException {
521+ type Args = FuncArgs ;
522+
523+ fn py_new ( cls : PyTypeRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
524+ PyBaseException :: new ( args. args , vm)
525+ . into_ref_with_type ( vm, cls)
526+ . map ( Into :: into)
527+ }
528+ }
529+
530+ impl Initializer for PyBaseException {
531+ type Args = FuncArgs ;
532+
533+ fn init ( zelf : PyRef < Self > , args : Self :: Args , vm : & VirtualMachine ) -> PyResult < ( ) > {
534+ * zelf. args . write ( ) = PyTuple :: new_ref ( args. args , & vm. ctx ) ;
535+ Ok ( ( ) )
536+ }
537+ }
538+
535539impl ExceptionZoo {
536540 pub ( crate ) fn init ( ) -> Self {
537541 use self :: types:: * ;
@@ -1119,6 +1123,7 @@ pub(super) mod types {
11191123 builtins:: { traceback:: PyTracebackRef , PyInt , PyTupleRef , PyTypeRef } ,
11201124 convert:: ToPyResult ,
11211125 function:: FuncArgs ,
1126+ types:: { Constructor , Initializer } ,
11221127 PyObjectRef , PyRef , PyResult , VirtualMachine ,
11231128 } ;
11241129 use crossbeam_utils:: atomic:: AtomicCell ;
@@ -1371,7 +1376,7 @@ pub(super) mod types {
13711376
13721377 new_args. args . truncate ( 2 ) ;
13731378 }
1374- PyBaseException :: init ( zelf, new_args, vm)
1379+ PyBaseException :: slot_init ( zelf, new_args, vm)
13751380 }
13761381
13771382 define_exception ! {
0 commit comments