`get_function_signature_hook` is not invoked on function decorators
維護者通常 1 天內回覆
評估
研究方向
使用 plug.py 中的 plugin 對 foo.py 重現程式碼執行 mypy,並比較針對 foo.deco 的 get_function_hook 和 get_function_signature_hook 呼叫。追蹤 decorator 呼叫的 plugin dispatch 路徑,並新增或更新 coverage,使 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.7k
- 分支
- 3.3k
- 平均合併
- 1 天 20 小時
- 30 天內合併 PR
- 102
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/mypy 的其他 Issue
-
T-string below Python 3.14 also reports import-not-found for string.templatelib on line 1可能已有人在做 @jw9829 今天認領。 未關閉bug topic-parser
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
Regression in 2.4.0: empty constraint tuple in PEP 695 type parameter (`class C[T: ()]`) is no longer reported可能已有人在做 @CheerathAniketh 於 2 天前認領。 未關閉topic-parser topic-pep-695
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
`stubgen --inspect-mode` crashes with `AttributeError on PEP 604 union syntax (X | Y)` *(mypy 2.1.0)*可能已有人在做 @ayushdoesdev 於 69 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
Inconsistent description of `strict_optional`可能已有人在做 @Joosboy 於 85 天前認領。 未關閉documentation
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
huggingface/peft#3955 ·
維護者通常 1 天內回覆
-
author-page correction
難度 2/5 1-3 小時 新手友好度 60/100
acl-org/acl-anthology#10313 ·
維護者通常 1 天內回覆
-
anime duplicate exception request-theme
難度 1/5 1 小時以內 新手友好度 82/100
LizardByte/ThemerrDB#8926 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
huggingface/transformers#49556 ·
維護者通常 1 天內回覆
-
area/security bug
難度 2/5 1-3 小時 新手友好度 82/100
mozilla-ai/otari#2245 ·
維護者通常 1 天內回覆