Replace `float` with `float | int`
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ả
As discussed in python/typing#1748: I propose to (slowly) replace float with float | int and complex with complex | float | int, where applicable.
- It's more correct, even if
floatis current implicitly equivalent toint | float. - We are already prepared should the implicit promotion ever be removed.
- We give type checkers the ability to optionally disable the promotion so that type checker authors and users can experiment with it.
- Typeshed would always need to be the first step for this, so let's remove this blocker.
This issue proposes an ugly and slow, but correct and safe procedure:
- Disable flake8-pyi code Y041.
#16096 - Introduce two type aliases
FloatInt = float | intandComplexInt = complex | float | intto_typeshed.
#16068 - Globally replace all instances of
floatwithFloatIntand ofcomplexwithComplexIntin the stdlib. - After 2026-09-22 we do the same for third-party stubs.
- Review
FloatIntandComplexIntinstances are replace them with the proper types. (This will take a while.) - Remove the type aliases once they are not needed anymore (in 10 years or so ...)
Using FloatInt and ComplexInt would be disallowed for new code and the type aliases should explicitly be marked as not to be used by non-typeshed code.
We should also probably add flake8-pyi checks that checks that argument types use float | int and complex | float | int. Cases where only float/complex is allowed are probably rare.
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 với các stub của stdlib và các alias FloatInt và ComplexInt trong _typeshed, sau đó kiểm tra cấu hình Y041 của flake8-pyi. Tìm kiếm các annotation float và complex trên toàn bộ stdlib và xem xét từng ứng viên; hoàn thành nghĩa là thực hiện migration stdlib trên toàn bộ phạm vi đã lên kế hoạch, còn các stub của bên thứ ba vẫn được hoãn đến 2026-09-22.
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
- Tái cấu trúc
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100