`get_function_signature_hook` is not invoked on function decorators
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
It seems to me there is no way to intercept and change the signature of a decorator during the invocation.
I see that get_function_hook has been called for foo.deco (eventually allowing me to change the return type of the decorator) but get_function_signature_hook is missing
To Reproduce
very basic example:
foo.py
from collections.abc import Callable
def deco(fun: Callable[..., None]) -> None: ...
@deco
def fun() -> None: ...
plug.py
from mypy.plugin import *
from mypy.types import *
from collections.abc import Callable
class CustomPlugin(Plugin):
def get_function_hook(self, fullname: str) -> Callable[[FunctionContext], Type] | None:
print(f'get_function_hook - {fullname=}')
return None
def get_function_signature_hook(self, fullname: str) -> Callable[[FunctionSigContext], FunctionLike] | None:
print(f'get_function_signature_hook - {fullname=}')
return None
def plugin(_version: str, /) -> type[Plugin]:
return CustomPlugin
If I run mypy with the plugin and capture the stdout I get (avoiding the duplicates):
get_function_hook - fullname='enum.auto'
get_function_hook - fullname='foo.deco'
get_function_hook - fullname='<list>'
get_function_hook - fullname='typing_extensions.disjoint_base'
get_function_hook - fullname='typing_extensions.final'
get_function_hook - fullname='typing.final'
get_function_hook - fullname='typing.runtime_checkable'
get_function_hook - fullname='typing.type_check_only'
get_function_hook - fullname='warnings.deprecated'
get_function_signature_hook - fullname='enum.auto'
get_function_signature_hook - fullname='warnings.deprecate
Expected Behavior
get_function_signature_hook is called also for foo.deco
Actual Behavior
it's missing
Your Environment
mypy 2.3.1 (compiled: yes)
Python 3.14.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run mypy on the foo.py reproduction with the plugin in plug.py, and compare the calls to get_function_hook and get_function_signature_hook for foo.deco. Trace the plugin dispatch path for decorator invocation and add or update coverage so the signature hook is invoked for foo.deco; done means the expected callback appears without breaking existing hook behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100