def _measurement_key_names_from_magic_methods(
    val: Any,
) -> frozenset[str] | NotImplementedType | None:
    """Uses the measurement key related magic methods to get the key strings for this object."""

    getter = getattr(val, '_measurement_key_names_', None)
    result = NotImplemented if getter is None else getter()
    if result is not NotImplemented and result is not None:
        return result

    getter = getattr(val, '_measurement_key_name_', None)
    result = NotImplemented if getter is None else getter()
    if result is not NotImplemented and result is not None:
        return frozenset([result])

    return result
Uses the measurement key related magic methods to get the key strings for this object.
cirq-core/cirq/protocols/measurement_key_protocol.py