code: def move_leadership(self, partition, new_leader):
          
          new_state = copy(self)
  
          # Update the partition replica tuple
          source = new_state.replicas[partition][0]
          new_leader_index = self.replicas[partition].index(new_leader)
          new_state.replicas = tuple_alter(
              self.replicas,
              (partition, lambda replicas: tuple_replace(
                  replicas,
                  (0, replicas[new_leader_index]),
                  (new_leader_index, replicas[0]),
              )),
          )
  
          new_state.pending_partitions = self.pending_partitions + (partition, )
  
          # Update the leader count
          new_state.broker_leader_counts = tuple_alter(
              self.broker_leader_counts,
              (source, lambda leader_count: leader_count - 1),
              (new_leader, lambda leader_count: leader_count + 1),
          )
  
          # Update the broker leader weights
          partition_weight = self.partition_weights[partition]
          new_state.broker_leader_weights = tuple_alter(
              self.broker_leader_weights,
              (source, lambda leader_weight: leader_weight - partition_weight),
              (new_leader, lambda leader_weight: leader_weight + partition_weight),
          )
  
          # Update the total leader movement size
          new_state.leader_movement_count += 1
  
          return new_state
docs: Return a new state that is the result of changing the leadership of
          a single partition.
  
          :param partition: The partition index of the partition to change the
              leadership of.
          :param new_leader: The broker index of the new leader replica.