@@ -835,39 +835,37 @@ check against. This is equivalent to isinstance(x, A) or isinstance(x, B)
835
835
or ... etc.
836
836
`
837
837
838
- func isinstance (args py.Tuple ) (py.Bool , error ) {
839
- switch args [1 ].(type ) {
838
+ func isinstance (obj py.Object , classOrTuple py.Object ) (py.Bool , error ) {
839
+ print (obj .Type ().Name , "\t " , classOrTuple .Type ().Name , "\n " )
840
+ switch classOrTuple .(type ) {
840
841
case py.Tuple :
841
- {
842
- var res py.Bool
843
- var class = args [1 ].(py.Tuple )
844
- for idx := range class {
845
- var new_args []py.Object
846
- new_args = append (new_args , args [0 ], class [idx ])
847
- temp , err := isinstance (new_args )
848
- if err != nil {
849
- return false , err
850
- }
851
- res = res || temp
842
+ var res py.Bool
843
+ var class_tuple = classOrTuple .(py.Tuple )
844
+ for idx := range class_tuple {
845
+ temp , err := isinstance (obj , class_tuple [idx ])
846
+ if err != nil {
847
+ return false , err
852
848
}
853
- return res , nil
849
+ res = res || temp
854
850
}
851
+ return res , nil
855
852
default :
856
- {
857
- if args [0 ].Type () != py .TypeType {
858
- return false , py .ExceptionNewf (py .TypeError , "isinstance() arg 2 must be a type or tuple of types" )
859
- }
860
- return args [0 ].Type () == args [1 ], nil
853
+ if classOrTuple .Type ().ObjectType != py .TypeType {
854
+ return false , py .ExceptionNewf (py .TypeError , "isinstance() arg 2 must be a type or tuple of types" )
861
855
}
856
+ return obj .Type () == classOrTuple , nil
862
857
}
863
858
}
864
859
865
860
func builtin_isinstance (self py.Object , args py.Tuple ) (py.Object , error ) {
866
- if len (args ) > 2 {
867
- return nil , py .ExceptionNewf (py .TypeError , "isinstance expected 2 arguments, got %d" , len (args ))
861
+ var obj py.Object
862
+ var classOrTuple py.Object
863
+ err := py .UnpackTuple (args , nil , "isinstance" , 2 , 2 , & obj , & classOrTuple )
864
+ if err != nil {
865
+ return nil , err
868
866
}
869
867
870
- return isinstance (args )
868
+ return isinstance (obj , classOrTuple )
871
869
}
872
870
873
871
const iter_doc = `iter(iterable) -> iterator
0 commit comments