def _expand_tasks(self, scopes):
    expanded_scopes = set(scopes)
    for scope, info in self._scope_to_info.items():
      if info.category == ScopeInfo.TASK:
        outer = enclosing_scope(scope)
        while outer != GLOBAL_SCOPE:
          if outer in expanded_scopes:
            expanded_scopes.add(scope)
            break
          outer = enclosing_scope(outer)
    return sorted(expanded_scopes)