Truthiness of None Does not Narrow Optional Types
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues
Please provide more information to help us understand the issue:
-
Are you reporting a bug, or opening a feature request?
I believe this is a bug -
Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
from typing import Optional
def the_method(maybe_int: Optional[int]):
can_divide = bool(maybe_int)
if can_divide:
100 / maybe_int
- What is the actual behavior/output?
error: Unsupported operand types for / ("int" and "None")
-
What is the behavior/output you expect?
I would think that the conditional branch would recognize that onlyintvalues would ever make it there -
What are the versions of mypy and Python you are using?
mypy 0.720 with Python 3.7.3 -
Do you see the same issue after installing mypy from Git master?
Yes still exists on master
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 bản tái hiện Python tối thiểu trong issue và lần theo điểm vào của việc thu hẹp kiểu dựa trên truthiness của mypy. Báo cáo không nêu tên tệp nguồn hay bài kiểm thử nào; được xem là hoàn thành khi nhánh điều kiện thu hẹp Optional[int] đủ để 100 / maybe_int vượt qua kiểm tra kiểu, kèm theo độ bao phủ hồi quy.
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
- compilers
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100