spec/conformance: function with TypeVar default and default argument used in context.
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Bắt đầu bằng cách xác định bộ kiểm thử tính tuân thủ của typing và các kiểm thử hiện có cho giá trị mặc định của TypeVar và các đối số mặc định. Thêm ví dụ Getter được đề xuất cùng với định nghĩa dự kiến và các chẩn đoán phép gán dự kiến, sau đó so sánh kết quả giữa các type checker được liệt kê để kỳ vọng về tính tuân thủ được thể hiện rõ ràng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I want to suggest adding the following test to the conformance test suite:
class Getter[T]:
def get[S=None](self, default: S = None) -> T | S: ... # OK
def test(arg: Getter[str]) -> None:
result: str = arg.get() # type: ignore
- Since the default argument value is assignable to the default type var type,
def getis well-defined arg.get()implicitly usesNoneof typeNoneas the argument. Therefore, we have an implicit constraintS <: Nonewhen.getis called without explicit default.
Therefore, result: str = arg.get() should raise an assignment type error (str | None not assignalbe to str).
Currently, only pyright succeeds on this test, and type checker results diverge.
pyright: no errors (true negative ondef get, true positive onresult) (pyright playground)mypy: false positive ondef get, false negative onresult.ty: false positive ondef get, true positive onresult. (playground)pyrefly: false positive ondef get, false negative onresult(playground)zuban: false postive ondef get, false negative onresult.
Related Issues
- https://github.com/python/mypy/issues/3737 (one of the most upvotes issues on mypy)
- https://github.com/astral-sh/ty/issues/592
- Ngôn ngữ chính
- Python
- Star
- 1.8k
- Fork
- 302
- Merge trung bình
- 23 giờ
- Pull request đã merge (30 ngày)
- 8
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.
Issue khác của python/typing
-
topic: typing spec
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
topic: typing spec
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
topic: documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
topic: documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
topic: conformance tests topic: typing spec
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
Tất cả issue của python/typing
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
zostera/django-bootstrap4#894 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
use-agent-os/agent-os#3276 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·