def all_bases(obj):
    """
    Return all the class to which ``obj`` belongs.
    """

    def _inner(thing, bases=None):
        bases = bases or set()
        if not hasattr(thing, "__bases__"):
            thing = thing.__class__
        for i in thing.__bases__ or []:
            bases.add(i)
            bases = bases | _inner(i, bases=bases)
        return bases

    return set(_inner(obj))