nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, typed_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, identifier:section; 15, type; 16, identifier:order; 17, None; 18, comment:"""Order is defined by the current state of sorting"""; 19, assignment; 20, assignment; 21, call; 22, comparison_operator:section == old_i; 23, block; 24, else_clause; 25, call; 26, identifier:int; 27, identifier:attr; 28, subscript; 29, pattern_list; 30, attribute; 31, attribute; 32, argument_list; 33, identifier:section; 34, identifier:old_i; 35, expression_statement; 36, expression_statement; 37, block; 38, attribute; 39, argument_list; 40, attribute; 41, identifier:section; 42, identifier:old_i; 43, identifier:old_sort; 44, identifier:self; 45, identifier:sort_state; 46, identifier:self; 47, identifier:beginResetModel; 48, call; 49, assignment; 50, expression_statement; 51, expression_statement; 52, identifier:self; 53, identifier:endResetModel; 54, identifier:self; 55, identifier:header; 56, attribute; 57, argument_list; 58, attribute; 59, tuple; 60, call; 61, assignment; 62, attribute; 63, identifier:sort; 64, identifier:attr; 65, not_operator; 66, identifier:self; 67, identifier:sort_state; 68, identifier:section; 69, not_operator; 70, attribute; 71, argument_list; 72, attribute; 73, tuple; 74, identifier:self; 75, identifier:collection; 76, identifier:old_sort; 77, identifier:old_sort; 78, attribute; 79, identifier:sort; 80, identifier:attr; 81, True; 82, identifier:self; 83, identifier:sort_state; 84, identifier:section; 85, True; 86, identifier:self; 87, identifier:collection
code: def sort(self, section: int, order=None):
          """Order is defined by the current state of sorting"""
          attr = self.header[section]
          old_i, old_sort = self.sort_state
          self.beginResetModel()
          if section == old_i:
              self.collection.sort(attr, not old_sort)
              self.sort_state = (section, not old_sort)
          else:
              self.collection.sort(attr, True)
              self.sort_state = (section, True)
          self.endResetModel()