@@ -893,16 +893,29 @@ dummy_func(void) {
893893 }
894894 JitOptSymbol * cls_sym = args [1 ];
895895 JitOptSymbol * inst_sym = args [0 ];
896+
896897 if (sym_is_const (ctx , cls_sym ) && sym_matches_type (cls_sym , & PyType_Type )) {
898+ // isinstance(obj, cls) where cls is a known class
897899 PyTypeObject * cls = (PyTypeObject * )sym_get_const (ctx , cls_sym );
898- if (sym_matches_type (inst_sym , cls )) {
899- res = sym_new_const (ctx , Py_True );
900+
901+ if (sym_has_type (inst_sym )) {
902+ // isinstance(obj, cls) where both obj and cls have known types
903+ // We can deduce either True or False
904+ PyTypeObject * inst_type = sym_get_type (inst_sym );
905+ if (sym_matches_type (inst_sym , cls ) || PyType_IsSubtype (inst_type , cls )) {
906+ res = sym_new_const (ctx , Py_True );
907+ }
908+ else {
909+ res = sym_new_const (ctx , Py_False );
910+ }
900911 }
901912 else {
913+ // isinstance(obj, cls) where obj has unknown type
902914 res = sym_new_type (ctx , & PyBool_Type );
903915 }
904916 }
905917 else {
918+ // isinstance(obj, cls) where cls has unknown type
906919 res = sym_new_type (ctx , & PyBool_Type );
907920 }
908921 }
0 commit comments