python / python/mypy

Coverage status reported for "not TYPE_CHECKING" blocks

Đang mở
#6,101 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

priority-1-normal topic-usability
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

Mô tả

I'm not sure whether this qualifies as a bug, feature request or discussion.

I have a code base that I want to be able to run on Python 3.5 (the version in Debian stable at the moment), without introducing additional runtime dependencies (depending on typing_extensions while type checking is fine, but I don't want to force every end user to install it). Therefore, I made the following workaround for NoReturn:

# NoReturn was introduced in Python 3.6.5.
if TYPE_CHECKING:
	from typing_extensions import NoReturn
else:
	NoReturn = None

This works fine, both at runtime and when type checking. However, when I ask mypy to produce a coverage report, the NoReturn = None line shows up red.

Other code I put in the else body, for example a print statement, also shows up red. My guess is that mypy doesn't type check the else body because TYPE_CHECKING is True and then marks all code that it doesn't have information on as red.

I use the coverage report to see if there is anything regarding type hinting that can be improved in modules and these red lines from not TYPE_CHECKING blocks are noise that makes it harder to spot areas that could be improved. So for my use case, it would be better if blocks that are deliberately unchecked would be marked in either green or a new low-attention color like white or grey.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách lần theo cách mypy xử lý báo cáo coverage cho các nhánh TYPE_CHECKING và so sánh cách phần thân else được phân loại. Công việc hoàn tất khi mã cố ý không được kiểm tra trong các khối not TYPE_CHECKING không còn xuất hiện dưới dạng coverage đỏ cần xử lý, trong khi mã thông thường chưa được bao phủ vẫn có thể phân biệt được.

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
devtools
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
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.