nodes: 0, module; 1, function_definition; 2, function_name:_sorted_by_priority; 3, parameters; 4, block; 5, identifier:self; 6, identifier:fmtos; 7, default_parameter; 8, expression_statement; 9, function_definition; 10, function_definition; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, while_statement; 16, identifier:changed; 17, None; 18, comment:"""Sort the formatoption objects by their priority and dependency
  
          Parameters
          ----------
          fmtos: list
              list of :class:`Formatoption` instances
          changed: list
              the list of formatoption keys that have changed
  
          Yields
          ------
          Formatoption
              The next formatoption as it comes by the sorting
  
          Warnings
          --------
          The list `fmtos` is cleared by this method!"""; 19, function_name:pop_fmto; 20, parameters; 21, block; 22, function_name:get_children; 23, parameters; 24, block; 25, call; 26, assignment; 27, assignment; 28, call; 29, identifier:fmtos; 30, block; 31, identifier:key; 32, expression_statement; 33, delete_statement; 34, return_statement; 35, identifier:fmto; 36, identifier:parents_keys; 37, expression_statement; 38, for_statement; 39, attribute; 40, argument_list; 41, identifier:fmtos_keys; 42, list_comprehension; 43, attribute; 44, boolean_operator; 45, attribute; 46, argument_list; 47, delete_statement; 48, expression_statement; 49, comment:# first update children; 50, for_statement; 51, comment:# filter out if parent is in update list; 52, if_statement; 53, expression_statement; 54, assignment; 55, subscript; 56, call; 57, assignment; 58, identifier:key; 59, binary_operator:fmto.children + fmto.dependencies; 60, block; 61, identifier:fmtos; 62, identifier:sort; 63, keyword_argument; 64, keyword_argument; 65, attribute; 66, for_in_clause; 67, identifier:self; 68, identifier:_last_update; 69, identifier:changed; 70, subscript; 71, attribute; 72, identifier:debug; 73, string:"Update the formatoptions %s"; 74, identifier:fmtos_keys; 75, subscript; 76, assignment; 77, identifier:child_fmto; 78, call; 79, block; 80, call; 81, block; 82, yield; 83, identifier:idx; 84, call; 85, identifier:fmtos_keys; 86, identifier:idx; 87, attribute; 88, argument_list; 89, identifier:all_fmtos; 90, binary_operator:fmtos_keys + parents_keys; 91, attribute; 92, attribute; 93, if_statement; 94, expression_statement; 95, for_statement; 96, comment:# filter out if parent is in update list; 97, if_statement; 98, expression_statement; 99, identifier:key; 100, lambda; 101, identifier:reverse; 102, True; 103, identifier:fmto; 104, identifier:key; 105, identifier:fmto; 106, identifier:fmtos; 107, identifier:fmtos_keys; 108, slice; 109, identifier:self; 110, identifier:logger; 111, identifier:fmtos_keys; 112, integer:0; 113, identifier:fmto; 114, call; 115, identifier:get_children; 116, argument_list; 117, expression_statement; 118, identifier:any; 119, generator_expression; 120, continue_statement; 121, identifier:fmto; 122, attribute; 123, argument_list; 124, identifier:fmtos; 125, identifier:pop; 126, identifier:idx; 127, identifier:fmtos_keys; 128, identifier:parents_keys; 129, identifier:fmto; 130, identifier:children; 131, identifier:fmto; 132, identifier:dependencies; 133, comparison_operator:key not in fmtos_keys; 134, block; 135, assignment; 136, identifier:childs_child; 137, call; 138, block; 139, parenthesized_expression; 140, block; 141, yield; 142, lambda_parameters; 143, attribute; 144, attribute; 145, argument_list; 146, identifier:fmto; 147, list; 148, yield; 149, comparison_operator:key in fmtos_keys; 150, for_in_clause; 151, identifier:fmtos_keys; 152, identifier:index; 153, identifier:key; 154, identifier:key; 155, identifier:fmtos_keys; 156, continue_statement; 157, identifier:child_fmto; 158, call; 159, identifier:get_children; 160, argument_list; 161, expression_statement; 162, boolean_operator; 163, continue_statement; 164, identifier:child_fmto; 165, identifier:fmto; 166, identifier:fmto; 167, identifier:priority; 168, identifier:fmtos; 169, identifier:pop; 170, integer:0; 171, attribute; 172, identifier:child_fmto; 173, identifier:key; 174, identifier:fmtos_keys; 175, identifier:key; 176, attribute; 177, identifier:pop_fmto; 178, argument_list; 179, identifier:child_fmto; 180, binary_operator:parents_keys + [child_fmto.key]; 181, yield; 182, call; 183, comparison_operator:fmto.key in child_fmto.parents; 184, identifier:fmto; 185, identifier:key; 186, identifier:fmto; 187, identifier:parents; 188, identifier:key; 189, identifier:parents_keys; 190, list; 191, identifier:childs_child; 192, identifier:any; 193, generator_expression; 194, attribute; 195, attribute; 196, attribute; 197, comparison_operator:key in all_fmtos; 198, for_in_clause; 199, identifier:fmto; 200, identifier:key; 201, identifier:child_fmto; 202, identifier:parents; 203, identifier:child_fmto; 204, identifier:key; 205, identifier:key; 206, identifier:all_fmtos; 207, identifier:key; 208, attribute; 209, identifier:child_fmto; 210, identifier:parents
code: def _sorted_by_priority(self, fmtos, changed=None):
          """Sort the formatoption objects by their priority and dependency
  
          Parameters
          ----------
          fmtos: list
              list of :class:`Formatoption` instances
          changed: list
              the list of formatoption keys that have changed
  
          Yields
          ------
          Formatoption
              The next formatoption as it comes by the sorting
  
          Warnings
          --------
          The list `fmtos` is cleared by this method!"""
          def pop_fmto(key):
              idx = fmtos_keys.index(key)
              del fmtos_keys[idx]
              return fmtos.pop(idx)
  
          def get_children(fmto, parents_keys):
              all_fmtos = fmtos_keys + parents_keys
              for key in fmto.children + fmto.dependencies:
                  if key not in fmtos_keys:
                      continue
                  child_fmto = pop_fmto(key)
                  for childs_child in get_children(
                          child_fmto, parents_keys + [child_fmto.key]):
                      yield childs_child
                  # filter out if parent is in update list
                  if (any(key in all_fmtos for key in child_fmto.parents) or
                          fmto.key in child_fmto.parents):
                      continue
                  yield child_fmto
  
          fmtos.sort(key=lambda fmto: fmto.priority, reverse=True)
          fmtos_keys = [fmto.key for fmto in fmtos]
          self._last_update = changed or fmtos_keys[:]
          self.logger.debug("Update the formatoptions %s", fmtos_keys)
          while fmtos:
              del fmtos_keys[0]
              fmto = fmtos.pop(0)
              # first update children
              for child_fmto in get_children(fmto, [fmto.key]):
                  yield child_fmto
              # filter out if parent is in update list
              if any(key in fmtos_keys for key in fmto.parents):
                  continue
              yield fmto