FWIW: I started using following approach: (get current instruction from the frame obj. and detect if it is a YIELD or not)
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION == 14
unsigned char curr_op_code = (*frame->f_frame->instr_ptr).op.code;
return curr_op_code == YIELD_VALUE || curr_op_code == INSTRUMENTED_YIELD_VALUE;
#elif PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION == 13
Related PR: Fix #193: Invalid coroutine state in `RETURN` event by sumerc · Pull Request #194 · sumerc/yappi · GitHub
Tests are green but this is a hackish way to do this kind of thing. I am hoping maybe we can somehow improve the situation for sys.setprofile hook?