Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`get_function_signature_hook` is not invoked on function decorators

Đang mở
#21,904 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
compilers, devtools

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 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

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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/mypy

Tất cả issue của python/mypy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.