Let's make this a val.  You can do

    val partNum: Int = {
      if (...) {
        rdds(0)._2.asInstanceOf[RDD[(_, _)]].partitioner.get.numPartitions
      } else {
        numReduceTasks
      }
    }