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

Remove follow_wrapped=False when getting signatures #82

Open
JelleZijlstra opened this issue Mar 14, 2021 · 1 comment
Open

Remove follow_wrapped=False when getting signatures #82

JelleZijlstra opened this issue Mar 14, 2021 · 1 comment

Comments

@JelleZijlstra
Copy link
Contributor

In signature.py, we use follow_wrapped=False when getting the signature of a callable:

return inspect.signature(obj, follow_wrapped=False)

It would be nice if we don't, because that will allow us to get accurate signatures for more decorated functions. When I tried this, it caused problems with some decorators that modify the function's signature but use @functools.wrap, notably @mock.patch (which passes additional arguments to the decorated function). I've also run into issues with @contextlib.contextmanager, which changes the return type of the decorated function.

Possible solutions:

  • Modify these decorators to set an accurate .__signature__ attribute on the decorated function (but that's not an option for third-party decorators)
  • Add special casing for some of these. For example, patched functions have a .patchings attribute; we could internally ignore the parameter corresponding to any entries in .patchings that have their .new attribute set to mock.DEFAULT. But there doesn't seem to be a similar way to identify a function that was decorated with @contextmanager.
@JelleZijlstra
Copy link
Contributor Author

#471 found a concrete place where this costs us type checking capabilities in pyanalyze's self check: methods annotated with qcore.caching.cached_per_instance().

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

1 participant