Call get_method_hook when methods are used in decorators #10675
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, when methods are used in decorators, instead of correctly calling
get_method_hook
with'{module_name}.{class_name}.{method_name}'
(withmodule_name
,class_name
, andmethod_name
filled in with their correct values),get_function_hook
is called instead with'{method_name} of {class_name}'
. This PR fixes this bug by callingget_method_hook
correctly.Technically, this may break some plugins if they relied on the fact that
get_function_hook
would be called on methods used in decorators, because with this PR those calls get moved toget_method_hook
. I'm guessing that this is rare, but I don't know for sure if any plugins rely on that.Currently, this only works when you access the method in the decorator itself, instead of assigning the method to a local variable. So, for example (assuming
obj
is an object that has a methodmeth
), this works:but this doesn't:
Currently, the second case causes mypy to pass
__main__.method
toget_function_hook
instead of passing the same thing as the first case. I added a test that's currently marked as xfail for the second case, but I'm not really sure how to fix it.Test Plan
I added a test to check-custom-plugin.test to make sure that the correct method name is getting passed to plugins and that it is getting passed to the correct plugin hook.