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? :) |
mhils
left a comment
There was a problem hiding this comment.
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