`get_function_signature_hook` is not invoked on function decorators
还没有人认领这个 Issue。
评估
调研方向
使用 plug.py 中的插件对 foo.py 复现代码运行 mypy,并比较针对 foo.deco 的 get_function_hook 和 get_function_signature_hook 调用。跟踪装饰器调用的插件 dispatch 路径,并添加或更新覆盖率,使 signature hook 针对 foo.deco 被调用;当预期的 callback 出现且不破坏现有 hook 行为时即表示完成。
由索引模型根据 Issue 内容生成。
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/mypy 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
-
documentation
难度 2/5 1-3 小时 新手友好度 72/100
-
bug topic-configuration topic-error-reporting
难度 2/5 1-3 小时 新手友好度 68/100
-
bug topic-attrs
难度 2/5 1-3 小时 新手友好度 62/100
相似的 Issue
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·