Not reporting any error when function returns bool type while expecting str type
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
- 38/100
Hướng nghiên cứu
Tái hiện hàm được báo cáo bằng mypy 0.782, Python 3.7.7 và các tùy chọn được liệt kê --strict-equality và --ignore-missing-imports, sau đó so sánh các chẩn đoán với lỗi kiểu giá trị trả về dự kiến. Truy vết đường đi của quá trình kiểm tra kiểu đối với các biểu thức trả về và các kiểu không xác định; được xem là hoàn tất khi hành vi đã được sửa hoặc được ghi tài liệu rõ ràng bằng một bài kiểm thử hồi quy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi
I noticed a situation where I wasn't getting a type error from mypy when I would have expected to get one.
Below is the code I have. I purposefully set the return type to str because I wanted to see a mypy error, and specifically I expected the error to be that I had set the wrong return type (e.g. as the code is doing a comparison, which will thus return a bool type, I expected mypy to say the return type should be of type bool):
def is_dev() -> str:
return settings.get("environment") == "dev"
In that code snippet you'll see settings.get(...), which is a function that returns a string, and we compare that string against another string.
Note: as
settings.getis custom code, mypy knows nothing about what type is being returned.
My hypothesis is that because my specific example uses code that mypy can't identify the type for (i.e. settings.get()), mypy just goes ahead and ignores any other possible type check errors (such as me specifying the return type as str).
If that's expected of mypy then fine, but it just confused me.
I'm using mypy version 0.782 and Python version 3.7.7.
I'm running mypy in two places:
- vim integration (e.g.
mypy --ignore-missing-imports --strict-equality) - tox (e.g.
mypy --ignore-missing-imports --package foo)
Note: I've tried also changing to
--no-strict-equalityand it makes no difference.
Thank you for any guidance you can give me.
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 54
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.
Issue khác của python/mypy
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug topic-configuration topic-error-reporting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Issue tương tự
-
link-check link-check:sphinx-theme
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100