List subclasses of a class
While working on the stack you are using stack.extend. You can also use this in the part where you add the immediate subclasses.
There is no need to check if a list is empty before using extend, if it is empty it will just do nothing.
If you don't need the exception, just don't catch it with as _.
Not sure if you should be doing if cls is type instead of if cls == type.




def all_subclasses(cls):

    if cls == type:
        raise ValueError("Invalid class - 'type' is not a class")

    subclasses = set()

    stack = []
    try:
        stack.extend(cls.__subclasses__())
    except (TypeError, AttributeError) as ex:
        raise ValueError("Invalid class" + repr(cls)) from ex  

    while stack:
        sub = stack.pop()
        subclasses.add(sub)
        try:
            stack.extend(sub.__subclasses__())
        except (TypeError, AttributeError):
           continue

    return list(subclasses)


One way to optimize this further is to make sure you don't visit a class multiple times:

    while stack:
        sub = stack.pop()
        subclasses.add(sub)
        try:
            stack.extend(s for s in sub.__subclasses__() if s not in subclasses)
        except (TypeError, AttributeError):
           continue


This should prevent having to visit (almost) every class twice with convoluted hierarchies like this:

    A
  /   \
 B     C
  \   /
    D
 / | | \
E  F G ...