diff options
Diffstat (limited to 'py/objtype.c')
-rw-r--r-- | py/objtype.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/py/objtype.c b/py/objtype.c index 46b96c7314..c814e9c75e 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -454,16 +454,7 @@ mp_obj_t mp_obj_new_super(mp_obj_t type, mp_obj_t obj) { /******************************************************************************/ // subclassing and built-ins specific to types -bool mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { - if (!MP_OBJ_IS_TYPE(object, &mp_type_type)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 1 must be a class")); - } - - // TODO support a tuple of classes for second argument - if (!MP_OBJ_IS_TYPE(classinfo, &mp_type_type)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 2 must be a class")); - } - +bool mp_obj_is_subclass_fast(mp_obj_t object, mp_obj_t classinfo) { for (;;) { if (object == classinfo) { return true; @@ -496,6 +487,19 @@ bool mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { } } +bool mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { + if (!MP_OBJ_IS_TYPE(object, &mp_type_type)) { + nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 1 must be a class")); + } + + // TODO support a tuple of classes for second argument + if (!MP_OBJ_IS_TYPE(classinfo, &mp_type_type)) { + nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 2 must be a class")); + } + + return mp_obj_is_subclass_fast(object, classinfo); +} + STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) { return MP_BOOL(mp_obj_is_subclass(object, classinfo)); } |