Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`get_function_signature_hook` is not invoked on function decorators

未关闭
#21,904 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python

调研方向

使用 plug.py 中的插件对 foo.py 复现代码运行 mypy,并比较针对 foo.deco 的 get_function_hook 和 get_function_signature_hook 调用。跟踪装饰器调用的插件 dispatch 路径,并添加或更新覆盖率,使 signature hook 针对 foo.deco 被调用;当预期的 callback 出现且不破坏现有 hook 行为时即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug topic-plugins

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

主要语言
Python
星标
20.6k
派生
3.3k
平均合并
1 天 12 小时
30 天内合并 PR
58

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python/mypy 的其他 Issue

查看 python/mypy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。