`get_function_signature_hook` is not invoked on function decorators
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Chạy mypy trên bản tái hiện foo.py với plugin trong plug.py, rồi so sánh các lần gọi get_function_hook và get_function_signature_hook cho foo.deco. Truy vết đường đi dispatch của plugin khi gọi decorator và thêm hoặc cập nhật coverage để signature hook được gọi cho foo.deco; hoàn tất khi callback mong đợi xuất hiện mà không làm hỏng hành vi hook hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 59
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/mypy
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug topic-configuration topic-error-reporting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
bug topic-attrs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
huggingface/Repo2RLEnv#163 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
NousResearch/hermes-agent#121143 ·