@@ -198,9 +198,9 @@ fn builtin_eval(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
198198 ) ;
199199
200200 // Determine code object:
201- let code_obj = if objtype:: isinstance ( source, & vm. ctx . code_type ( ) ) {
201+ let code_obj = if objtype:: real_isinstance ( source, & vm. ctx . code_type ( ) ) {
202202 source. clone ( )
203- } else if objtype:: isinstance ( source, & vm. ctx . str_type ( ) ) {
203+ } else if objtype:: real_isinstance ( source, & vm. ctx . str_type ( ) ) {
204204 let mode = compile:: Mode :: Eval ;
205205 let source = objstr:: get_value ( source) ;
206206 // TODO: fix this newline bug:
@@ -235,7 +235,7 @@ fn builtin_exec(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
235235 ) ;
236236
237237 // Determine code object:
238- let code_obj = if objtype:: isinstance ( source, & vm. ctx . str_type ( ) ) {
238+ let code_obj = if objtype:: real_isinstance ( source, & vm. ctx . str_type ( ) ) {
239239 let mode = compile:: Mode :: Exec ;
240240 let source = objstr:: get_value ( source) ;
241241 // TODO: fix this newline bug:
@@ -246,7 +246,7 @@ fn builtin_exec(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
246246 vm. new_exception ( syntax_error, err. to_string ( ) )
247247 } ,
248248 ) ?
249- } else if objtype:: isinstance ( source, & vm. ctx . code_type ( ) ) {
249+ } else if objtype:: real_isinstance ( source, & vm. ctx . code_type ( ) ) {
250250 source. clone ( )
251251 } else {
252252 return Err ( vm. new_type_error ( "source argument must be str or code object" . to_string ( ) ) ) ;
@@ -349,21 +349,25 @@ fn builtin_id(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
349349// builtin_input
350350
351351fn builtin_isinstance ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
352- arg_check ! ( vm, args, required = [ ( obj, None ) , ( typ, None ) ] ) ;
352+ arg_check ! (
353+ vm,
354+ args,
355+ required = [ ( obj, None ) , ( typ, Some ( vm. get_type( ) ) ) ]
356+ ) ;
353357
354- let isinstance = objtype:: isinstance ( obj, typ) ;
355- Ok ( vm. context ( ) . new_bool ( isinstance) )
358+ let isinstance = objtype:: isinstance ( vm , obj, typ) ? ;
359+ Ok ( vm. new_bool ( isinstance) )
356360}
357361
358362fn builtin_issubclass ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
359- if args. args . len ( ) != 2 {
360- panic ! ( "issubclass expects exactly two parameters" ) ;
361- }
362-
363- let cls1 = & args. args [ 0 ] ;
364- let cls2 = & args. args [ 1 ] ;
363+ arg_check ! (
364+ vm,
365+ args,
366+ required = [ ( subclass, Some ( vm. get_type( ) ) ) , ( cls, Some ( vm. get_type( ) ) ) ]
367+ ) ;
365368
366- Ok ( vm. context ( ) . new_bool ( objtype:: issubclass ( cls1, cls2) ) )
369+ let issubclass = objtype:: issubclass ( vm, subclass, cls) ?;
370+ Ok ( vm. context ( ) . new_bool ( issubclass) )
367371}
368372
369373fn builtin_iter ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
@@ -501,7 +505,7 @@ fn builtin_next(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
501505 match vm. call_method ( iterator, "__next__" , vec ! [ ] ) {
502506 Ok ( value) => Ok ( value) ,
503507 Err ( value) => {
504- if objtype:: isinstance ( & value, & vm. ctx . exceptions . stop_iteration ) {
508+ if objtype:: real_isinstance ( & value, & vm. ctx . exceptions . stop_iteration ) {
505509 match default_value {
506510 None => Err ( value) ,
507511 Some ( value) => Ok ( value. clone ( ) ) ,
@@ -581,7 +585,7 @@ pub fn builtin_print(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
581585 . get_optional_kwarg ( "sep" )
582586 . filter ( |obj| !obj. is ( & vm. get_none ( ) ) ) ;
583587 if let Some ( ref obj) = sep_arg {
584- if !objtype:: isinstance ( obj, & vm. ctx . str_type ( ) ) {
588+ if !objtype:: real_isinstance ( obj, & vm. ctx . str_type ( ) ) {
585589 return Err ( vm. new_type_error ( format ! (
586590 "sep must be None or a string, not {}" ,
587591 objtype:: get_type_name( & obj. typ( ) )
@@ -595,7 +599,7 @@ pub fn builtin_print(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
595599 . get_optional_kwarg ( "end" )
596600 . filter ( |obj| !obj. is ( & vm. get_none ( ) ) ) ;
597601 if let Some ( ref obj) = end_arg {
598- if !objtype:: isinstance ( obj, & vm. ctx . str_type ( ) ) {
602+ if !objtype:: real_isinstance ( obj, & vm. ctx . str_type ( ) ) {
599603 return Err ( vm. new_type_error ( format ! (
600604 "end must be None or a string, not {}" ,
601605 objtype:: get_type_name( & obj. typ( ) )
@@ -818,9 +822,9 @@ pub fn builtin_build_class_(vm: &mut VirtualMachine, mut args: PyFuncArgs) -> Py
818822 let mut metaclass = args. get_kwarg ( "metaclass" , vm. get_type ( ) ) ;
819823
820824 for base in bases. clone ( ) {
821- if objtype:: issubclass ( & base. typ ( ) , & metaclass) {
825+ if objtype:: issubclass ( vm , & base. typ ( ) , & metaclass) ? {
822826 metaclass = base. typ ( ) ;
823- } else if !objtype:: issubclass ( & metaclass, & base. typ ( ) ) {
827+ } else if !objtype:: real_issubclass ( & metaclass, & base. typ ( ) ) {
824828 return Err ( vm. new_type_error ( "metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases" . to_string ( ) ) ) ;
825829 }
826830 }
0 commit comments