def _qid_shape_from_args(
    num_qubits: int | None, qid_shape: tuple[int, ...] | None
) -> tuple[int, ...]:
    """Returns either `(2,) * num_qubits` or `qid_shape`.

    Raises:
        ValueError: If both arguments are None or their values disagree.
    """
    if num_qubits is None and qid_shape is None:
        raise ValueError(
            'Either the num_qubits or qid_shape argument must be specified. Both were None.'
        )
    if num_qubits is None:
        return cast(tuple[int, ...], qid_shape)
    if qid_shape is None:
        return (2,) * num_qubits
    if len(qid_shape) != num_qubits:
        raise ValueError(
            f'num_qubits != len(qid_shape). num_qubits was {num_qubits!r}. '
            f'qid_shape was {qid_shape!r}.'
        )
    return qid_shape
Returns either `(2,) * num_qubits` or `qid_shape`.

    Raises:
        ValueError: If both arguments are None or their values disagree.
    
cirq-core/cirq/qis/states.py