function is lacking a `__signature__` attribute
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 5.1k
- Fork
- 2.1k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 82
Mô tả
PEP-362 specifies that in order to cache the signature of any function, it is possible for the user to set its __signature__ attribute.
Actual
This attribute is not set in the builtins module over at https://github.com/python/typeshed/blob/main/stdlib/builtins.pyi#L1009
As a result a typechecker might reject the following piece of code
from inspect import signature
def main():
def f():
pass
f.__signature__ = signature(f)
if __name__ == "__main__":
main()
e.g. with pyright I have a false positive
/Users/leogermond/Lab/python/signature/main.py
/Users/leogermond/Lab/python/signature/main.py:9:7 - error: Cannot assign to attribute "__signature__" for class "function"
Attribute "__signature__" is unknown (reportFunctionMemberAccess)
1 error, 0 warnings, 0 informations
Expected
I would the __signature__ attribute to be specified in the function class (with a special marker indicating it's optional?) of the builtins module. A type checker such as pyright could then infer that setting this attribute is possible and accept the piece of code given in example.
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.
Hướng nghiên cứu
Bắt đầu tại stdlib/builtins.pyi, quanh dòng 1009, và kiểm tra cách function class được khai báo. So sánh hỗ trợ tùy chọn signature được yêu cầu với PEP 362 và ví dụ phép gán được cung cấp, sau đó xác minh rằng một trình kiểm tra kiểu như pyright chấp nhận nó khi thay đổi stub hoàn tất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- tooling
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 55/100