11use crate :: function:: PyFuncArgs ;
22use crate :: obj:: objsequence;
33use crate :: obj:: objtype;
4+ use crate :: obj:: objtype:: PyClassRef ;
45use crate :: pyobject:: { create_type, PyContext , PyObjectRef , PyResult , TypeProtocol } ;
56use crate :: vm:: VirtualMachine ;
67
@@ -65,7 +66,10 @@ fn exception_str(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
6566 arg_check ! (
6667 vm,
6768 args,
68- required = [ ( exc, Some ( vm. ctx. exceptions. exception_type. clone( ) ) ) ]
69+ required = [ (
70+ exc,
71+ Some ( vm. ctx. exceptions. exception_type. clone( ) . into_object( ) )
72+ ) ]
6973 ) ;
7074 let type_name = objtype:: get_type_name ( & exc. typ ( ) ) ;
7175 let msg = if let Ok ( m) = vm. get_attribute ( exc. clone ( ) , "msg" ) {
@@ -82,31 +86,31 @@ fn exception_str(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
8286
8387#[ derive( Debug ) ]
8488pub struct ExceptionZoo {
85- pub arithmetic_error : PyObjectRef ,
86- pub assertion_error : PyObjectRef ,
87- pub attribute_error : PyObjectRef ,
88- pub base_exception_type : PyObjectRef ,
89- pub exception_type : PyObjectRef ,
90- pub file_not_found_error : PyObjectRef ,
91- pub import_error : PyObjectRef ,
92- pub index_error : PyObjectRef ,
93- pub key_error : PyObjectRef ,
94- pub module_not_found_error : PyObjectRef ,
95- pub name_error : PyObjectRef ,
96- pub not_implemented_error : PyObjectRef ,
97- pub os_error : PyObjectRef ,
98- pub overflow_error : PyObjectRef ,
99- pub permission_error : PyObjectRef ,
100- pub runtime_error : PyObjectRef ,
101- pub stop_iteration : PyObjectRef ,
102- pub syntax_error : PyObjectRef ,
103- pub type_error : PyObjectRef ,
104- pub value_error : PyObjectRef ,
105- pub zero_division_error : PyObjectRef ,
89+ pub arithmetic_error : PyClassRef ,
90+ pub assertion_error : PyClassRef ,
91+ pub attribute_error : PyClassRef ,
92+ pub base_exception_type : PyClassRef ,
93+ pub exception_type : PyClassRef ,
94+ pub file_not_found_error : PyClassRef ,
95+ pub import_error : PyClassRef ,
96+ pub index_error : PyClassRef ,
97+ pub key_error : PyClassRef ,
98+ pub module_not_found_error : PyClassRef ,
99+ pub name_error : PyClassRef ,
100+ pub not_implemented_error : PyClassRef ,
101+ pub os_error : PyClassRef ,
102+ pub overflow_error : PyClassRef ,
103+ pub permission_error : PyClassRef ,
104+ pub runtime_error : PyClassRef ,
105+ pub stop_iteration : PyClassRef ,
106+ pub syntax_error : PyClassRef ,
107+ pub type_error : PyClassRef ,
108+ pub value_error : PyClassRef ,
109+ pub zero_division_error : PyClassRef ,
106110}
107111
108112impl ExceptionZoo {
109- pub fn new ( type_type : & PyObjectRef , object_type : & PyObjectRef ) -> Self {
113+ pub fn new ( type_type : & PyClassRef , object_type : & PyClassRef ) -> Self {
110114 // Sorted By Hierarchy then alphabetized.
111115 let base_exception_type = create_type ( "BaseException" , & type_type, & object_type) ;
112116 let exception_type = create_type ( "Exception" , & type_type, & base_exception_type) ;
@@ -159,13 +163,13 @@ impl ExceptionZoo {
159163pub fn init ( context : & PyContext ) {
160164 let base_exception_type = & context. exceptions . base_exception_type ;
161165 context. set_attr (
162- & base_exception_type,
166+ base_exception_type,
163167 "__init__" ,
164168 context. new_rustfunc ( exception_init) ,
165169 ) ;
166170 let exception_type = & context. exceptions . exception_type ;
167171 context. set_attr (
168- & exception_type,
172+ exception_type,
169173 "__str__" ,
170174 context. new_rustfunc ( exception_str) ,
171175 ) ;
0 commit comments