def _measurement_key_objs_from_magic_methods(
    val: Any,
) -> frozenset[cirq.MeasurementKey] | NotImplementedType | None:
    """Uses the measurement key related magic methods to get the `MeasurementKey`s for this
    object."""

    getter = getattr(val, '_measurement_key_objs_', 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_obj_', 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 `MeasurementKey`s for this
    object.
cirq-core/cirq/protocols/measurement_key_protocol.py