isinstance without importing candidates isinstance without importing candidates python python

isinstance without importing candidates


Using type(POSSIBLE_MATCHER).__name__ is IMHO a fairly elegant solution for type checking without having to import the module.


If you want to cater for inheritance, using type(POSSIBLE_MATCHER).__name__ will not cut it. You could then check against all types in the inheritance chain:

class_string in [t.__name__ for t in type(POSSIBLE_MATCHER).__mro__]