def with_observable(
        self, observable: cirq.BaseDensePauliString | Iterable[cirq.Pauli]
    ) -> PauliMeasurementGate:
        """Creates a pauli measurement gate with the new observable and same key."""
        if (
            observable
            if isinstance(observable, dps.BaseDensePauliString)
            else dps.DensePauliString(observable)
        ) == self._observable:
            return self
        return PauliMeasurementGate(observable, key=self.key)
Creates a pauli measurement gate with the new observable and same key.
cirq-core/cirq/ops/pauli_measurement_gate.py