You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like this idea, this will allow supporting some common dynamic features.
This will likely require local lookup functions to the public API (currently it is there on SemanticAnalyzer but not on SemanticAnalyzerPluginInterface).
JFI/bump: I wonder if this is only about having get_function_signature_hook (in line with get_method_signature_hook) - but from a quick test it seems like get_method_signature_hook also only gets called for method calls, not definitions.
I've also looked into this because of pytest.
We could have a hook that gets called after semantic analysis and before type checking that can adjust the signature of each function/method.
We could have a signature adjustment hook that gets called before type checking the body of a function. However, this seems more complicated -- for consistency, we also need another hook that gets called for function calls. The benefit here would be that the hook could access inferred types of other functions and attributes.
We could have a hook that gets called for each module after semantic analysis, which would allow arbitrary changes to module namespaces. However, the implementation would have to be pretty tightly coupled with the mypy symbol table and AST implementation, so this might not the best option. Also, this might not work well with mypy daemon.
We could have a signature adjustment hook that gets called before type checking the body of a function. However, this seems more complicated -- for consistency, we also need another hook that gets called for function calls. The benefit here would be that the hook could access inferred types of other functions and attributes.
JFI/bump: I wonder if this is only about having get_function_signature_hook (in line with get_method_signature_hook) - but from a quick test it seems like get_method_signature_hook also only gets called for method calls, not definitions. I've also looked into this because of pytest.
Related to this, I found that get_function_signature_hook is not called in this case (when a function is used as a decorator):
Is this the expected behavior? IMHO get_function_signature_hook should be called also when a function is used as a decorator since decorators are syntactical sugar. Should this be considered a bug?
Activity
ilevkivskyi commentedon May 3, 2019
I like this idea, this will allow supporting some common dynamic features.
This will likely require local lookup functions to the public API (currently it is there on
SemanticAnalyzerbut not onSemanticAnalyzerPluginInterface).blueyed commentedon Jan 10, 2020
JFI/bump: I wonder if this is only about having
get_function_signature_hook(in line withget_method_signature_hook) - but from a quick test it seems likeget_method_signature_hookalso only gets called for method calls, not definitions.I've also looked into this because of pytest.
JukkaL commentedon Jan 14, 2020
Brainstorming:
MrGreenTea commentedon May 15, 2020
I was quite suprised this is not already the case, as I understand it exists for classes / methods with the
get_method_signature_hookalready.What's the reasoning behind that decision? What would be needed to add such a hook?
sobolevn commentedon Jun 30, 2020
This looks like exactly what I am looking for here: https://gitter.im/python/typing?at=5efa750ee0e5673398e1aa81
TLDR:
This code currently does not typecheck, because it is not seem to be possible to tell what
Kindis in this context.sobolevn commentedon Mar 18, 2021
Related #9925
i386x commentedon Jun 29, 2026
Related to this, I found that
get_function_signature_hookis not called in this case (when a function is used as a decorator):but it is called in this case (when a function is used as a function):
Is this the expected behavior? IMHO
get_function_signature_hookshould be called also when a function is used as a decorator since decorators are syntactical sugar. Should this be considered a bug?ilevkivskyi commentedon Jun 29, 2026
Yes, I think this is a bug (but to be clear fixing it will not solve the original issue).