[WIP] Add get_function_decorator_plugin_hook to plugin interface #9925
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.
Description
Closes #9915
This PR adds the plugin hook I proposes in #9915.
Test Strategy
Two new unit tests have been added to test the new plugin hook
Q&A
Why is this plugin hook needed?:
This hook can be used to solve problems like for example #9911, which can't be solved by existing plugin hooks.
There is already a plugin hook for handling class decorators, but none for method and function decorators.
Why is there no
get_method_decorator_plugin_hook?:From what I can tell the semantic analysis phase doesn't distinguish between functions and methods. Therefor only one hook has been added. The other hooks, which have
functionandmethodvariants run during the checking phase.What can this hook do?
Mark decorated functions as properties, abstract, final and coroutines
What can't this hook do?
This hook currently can't disable type checking for decorated functions, despite the builtin '@typing.no_type_check' decorator being able to do so. Enabling this would require more code changes, as a local variable is used for this and would have to be exposed in some way.
When does this hook run?
This hook runs after the builtin code has handled the decorators, but before handled decorators are removed and the decorated function is semantically analyzed.
Additional considerations
SematicAnalyzer.check_decorated_function_is_methodon theSemanticAnalyzerPluginInterface