def assert_specifies_has_unitary_if_unitary(val: Any) -> None:
    """Checks that unitary values can be cheaply identifies as unitary."""

    # pylint: disable=unused-variable
    __tracebackhide__ = True
    # pylint: enable=unused-variable

    assert not protocols.has_unitary(val) or hasattr(val, '_has_unitary_'), (
        "Value is unitary but doesn't specify a _has_unitary_ method that "
        "can be used to cheaply verify this fact.\n"
        "\n"
        f"val: {val!r}"
    )
Checks that unitary values can be cheaply identifies as unitary.
cirq-core/cirq/testing/consistent_specified_has_unitary.py