This problem came up when developing a C library for using asynchronous Python functions from C (see this dicussion and this discussion). The solution right now is to use capsules, as shown above, but that limits the library to being used only from C (and C++, probably, but I’m not totally sure).