def check_classes(var, check):
  """Check whether the cls of each value in `var` is a class and passes `check`.

  Args:
    var: A cfg.Variable or empty.
    check: (BaseValue) -> bool.

  Returns:
    Whether the check passes.
  """
  return var and all(
      v.cls.isinstance_Class() and check(v.cls) for v in var.data if v.cls)