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

Cython functions aren't supported because of the way inspect.isfunction works #3

Open
wxd opened this issue Jan 20, 2021 · 4 comments

Comments

@wxd
Copy link

wxd commented Jan 20, 2021

inspect.isfunction returns False for Cython functions (see this discussion).

As a result, tracking pydantic.fields.ModelField.validate for pydantic==1.7.3 is impossible.

@sm-Fifteen
Copy link
Owner

Is this exclusive to Cython functions or would any C function cause that problem? Your mailing list thread links to pep-0575, which in turn links to pep-0579, and both seem to recommend making changes to inspect.isfunction that don't seem to have gone through.

There's always the possibility of just going the duck-typing route and searching for a __code__ attribute on the functions, possibly alongside an extra check to ensure the functions being passed aren't bound methods (which I believe didn't work with yappi, but I would have to double-check), which seems to be what's recommended in the case of Cython, but some testing will be needed in that regard.

@wxd
Copy link
Author

wxd commented Jan 20, 2021

I don't have any deep insight into this: I've found your repo while exploring different options for FastAPI profiling, tried to run the example in smoke_test.py, and hit that exception. So I only have an example of a Cython function.

I just tried replacing inspect.isfunction(profiled) with inspect.isroutine(profiled) (inspired by this), and it worked in the sense that Yappi didn't complain and returned YFuncStats containing Cython functions (and bound methods, too). The numbers look OK.

@wxd
Copy link
Author

wxd commented Jan 20, 2021

callable(profiled) might be another option. I'll check and report tomorrow.

@traviscook21
Copy link

FWIW - this stopped pydantic.fields.ModelField.validate (included in the readme) from working correctly because inspect.isfunction returns False. validate is a cython function.

Changing to callable(profiled) worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants