-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
get source_file of wrapped functions #657
Conversation
As an alternative, I thought about unwrapping cached functions in if isinstance(func, functools._lru_cache_wrapper): |
I haven't implemented test coverage for the two new methods in doc_ast yet. What kind of test would you like to have?
|
Does that fix source extraction? That seems like a reasonable approach here. We heavily depend on Python internals anyhow. If we're concerned about this being an internal API, we can also try the import in |
I removed the cached version of get_source_file from doc_ast.py and cached functions are unwrapped like this, now: elif hasattr(func, "__wrapped__"):
unwrapped = func.__wrapped__ According to the source code of functools, wrapped is part of the public API of |
Thanks, this looks great now. Can we get a test + changelog entry for this? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the super quick turnaround! 🍰
I added a function get_source_file to doc_ast.py that tries to get the source file from obj.wrapped if inspect.getsourcefile(obj) doesn't succeed.
I used the same cached approach as in doc_ast.get_source.
closes #656