import inspect


def get_object_classes(classes_or_instances, expected_base_class=None):
    """Given a list of instances or class objects, return the list of their classes.

    :param classes_or_instances: mixed list to parse
    :type classes_or_instances: list[type or object]
    :param expected_base_class: if given, only subclasses or instances of this type will be returned
    :type expected_base_class: type
    :return: list of classes
    :rtype: list
    """
    classes_or_instances = classes_or_instances or []
    result = []
    for obj in classes_or_instances:
        if inspect.isclass(obj):
            if not expected_base_class or issubclass(obj, expected_base_class):
                result.append(obj)
        else:
            if not expected_base_class or isinstance(obj, expected_base_class):
                result.append(type(obj))

    return result