Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPython create_autospec does not work with cyfunctions #3143

dhiltonp opened this issue Sep 13, 2019 · 0 comments


Copy link

commented Sep 13, 2019

Cython functions are not compatible with unittest.mock's create_autospec and asyncio's iscoroutinefunction when imported into a CPython module.

I'm not super familiar with the inner workings of cython and how it integrates with cpython, but getting the functions to work seems like the responsibility of cython, not cpython.

CPython's unittest.mock uses FunctionTypes, a tuple with 2 objects, to determine if an object is callable for the purposes of automatically creating a mock object.

Should Cython patch FunctionTypes to also include cyfunction types? Or is there a better way of making this change?

Additionally, CPython's asyncio.iscoroutinefunction cannot determine that a cythonized function is async.

iscoroutinefunction looks for one of two things: inspect saying it's a coroutine or the function having _is_coroutine assigned to a specific object (internal use).

I think the best way to do this is to make _has_code_flag(obj, CO_COROUTINE) return True for cython functions.

Pointers on what to modify in cython's code base are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.