Clarify the float/int/complex special case
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 1.8k
- Fork
- 302
- Merge trung bình
- 23 giờ
- Pull request đã merge (30 ngày)
- 8
Mô tả
The typing spec currently says this:
Python’s numeric types complex, float and int are not subtypes of each other, but to support common use cases, the type system contains a straightforward shortcut: when an argument is annotated as having type float, an argument of type int is acceptable; similar, for an argument annotated as having type complex, arguments of type float or int are acceptable.
This is helpful in that it clarifies that there is not a subtype relationship here. It remains unclear (to me, at least) in the following ways:
- It implies that this special case applies only to function argument annotations, and not to any other annotation (e.g. an annotation of the type of an attribute of a class). I find this surprising, but perhaps it is intended? I think it is surprising enough that if it's intended, the wording should be even clearer, and explicitly show examples where the special case does not apply outside an argument annotation.
- The wording "is acceptable" in the absence of a subtype relationship does not clarify how this special case actually fits into the type system; we can accept an
intto afloattyped argument, but then how do we type that name within the function body? If what we actually mean here is thatfloatshould be interpreted asfloat | int, then we should say that clearly.
There was some discussion of this on https://github.com/python/typing/issues/1663, which is about the different but related question of whether to mention the numeric tower and PEP 3141.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
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 với phần numeric-types được trích dẫn trong typing spec và xem lại thảo luận liên quan trong typing/issues/1663. Xác định liệu lối tắt chỉ áp dụng cho các đối số của hàm hay không và kiểu được chấp nhận được hiểu như thế nào bên trong hàm, sau đó cập nhật cách diễn đạt bằng các ví dụ và một định nghĩa chính xác về ý nghĩa của "done".
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
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100