'A recursive helper used to implement list_vars() in subclasses.'

def _rec_list_vars(self, val):

    if isinstance(val, Var):
        return [val]
    elif isinstance(val, Inst):
        return val.list_vars()
    elif isinstance(val, (list, tuple)):
        lst = []
        for v in val:
            lst.extend(self._rec_list_vars(v))
        return lst
    elif isinstance(val, dict):
        lst = []
        for v in val.values():
            lst.extend(self._rec_list_vars(v))
        return lst
    else:
        return []
