Skip to content

get_function_signature_hook is not invoked on function decorators #21904

Description

@ZeeD

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pluginsThe plugin API and ideas for new plugins

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions