def _phased_x_or_pauli_gate(
    exponent: float | sympy.Expr, phase_exponent: float | sympy.Expr
) -> cirq.PhasedXPowGate | cirq.XPowGate | cirq.YPowGate:
    """Return PhasedXPowGate or X or Y gate if equivalent at the given phase_exponent."""
    if not isinstance(phase_exponent, sympy.Expr) or phase_exponent.is_constant():
        half_turns = value.canonicalize_half_turns(float(phase_exponent))
        match half_turns:
            case 0.0:
                return XPowGate(exponent=exponent)
            case 0.5:
                return YPowGate(exponent=exponent)
    return cirq.ops.PhasedXPowGate(exponent=exponent, phase_exponent=phase_exponent)
Return PhasedXPowGate or X or Y gate if equivalent at the given phase_exponent.
cirq-core/cirq/ops/common_gates.py