nodes: 0, module; 1, function_definition; 2, function_name:_expand_tasks; 3, parameters; 4, block; 5, identifier:self; 6, identifier:scopes; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, return_statement; 11, comment:"""Add all tasks in any requested goals.
  
      Returns the requested scopes, plus the added tasks, sorted by scope name.
      """; 12, assignment; 13, pattern_list; 14, call; 15, block; 16, call; 17, identifier:expanded_scopes; 18, call; 19, identifier:scope; 20, identifier:info; 21, attribute; 22, argument_list; 23, if_statement; 24, identifier:sorted; 25, argument_list; 26, identifier:set; 27, argument_list; 28, attribute; 29, identifier:items; 30, comparison_operator:info.category == ScopeInfo.TASK; 31, block; 32, identifier:expanded_scopes; 33, identifier:scopes; 34, identifier:self; 35, identifier:_scope_to_info; 36, attribute; 37, attribute; 38, expression_statement; 39, while_statement; 40, identifier:info; 41, identifier:category; 42, identifier:ScopeInfo; 43, identifier:TASK; 44, assignment; 45, comparison_operator:outer != GLOBAL_SCOPE; 46, block; 47, identifier:outer; 48, call; 49, identifier:outer; 50, identifier:GLOBAL_SCOPE; 51, if_statement; 52, expression_statement; 53, identifier:enclosing_scope; 54, argument_list; 55, comparison_operator:outer in expanded_scopes; 56, block; 57, assignment; 58, identifier:scope; 59, identifier:outer; 60, identifier:expanded_scopes; 61, expression_statement; 62, break_statement; 63, identifier:outer; 64, call; 65, call; 66, identifier:enclosing_scope; 67, argument_list; 68, attribute; 69, argument_list; 70, identifier:outer; 71, identifier:expanded_scopes; 72, identifier:add; 73, identifier:scope
code: def _expand_tasks(self, scopes):
      """Add all tasks in any requested goals.
  
      Returns the requested scopes, plus the added tasks, sorted by scope name.
      """
      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)