def class_filter(dataset, classes, is_superclass=False, proportion=1.0):
  """
  Handles filtering of (super)classes for use with tf.Dataset.

  Arguments:
    dataset: An instance of the Dataset class.
    classes: A list of classes (or superclasses).
    is_superclass: A flag indicate whether or not the "classes" param consists of superclasses.
    proportion: A float indicating the proportion of classes to retrieve.
  """
  output_classes = []

  try:
    if classes and is_superclass:
      output_classes = dataset.get_classes_by_superclass(classes, proportion)
    elif classes and not is_superclass:
      output_classes = [int(x) for x in classes]
  except:
    raise ValueError('Failed to filter classes.')

  return output_classes