python / python/typing

Finals and Literals: Spec contradiction

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

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

topic: conformance tests topic: typing spec
Ngôn ngữ chính
Python
Star
1.8k
Fork
302
Merge trung bình
23 giờ
Pull request đã merge (30 ngày)
8

Mô tả

This came up in python/typeshed#16301. I assume this is mostly a clerical/historical error, but let me know if we should follow the whole spec change process.


The typing spec says about Final:

Example:

ID: Final = 1

The typechecker should apply its usual type inference mechanisms to determine the type of ID (here, likely, int).

And then a bit later:

Type checkers should treat uses of a final name that was initialized with a literal as if it was replaced by the literal.

Both sentences are copied directly from PEP 591, which overlapped with the Literals PEP 586.

I assume that we should change the first sentence to "here, likely, Literal[1]" and change the second sentence to be a bit more concrete along these lines:

Type checkers should infer uses of a final name that was initialized with a literal X as Literal[X] if X is an allowed literal type (cf. to the literals section). Otherwise, they should infer the type of the X.

(And maybe extend the example after a bit.)

In fact, this is what the conformance tests already check:

https://github.com/python/typing/blob/cf943ccbea5596ef969eec6e2260097ff697b7ba/conformance/tests/qualifiers_final_annotation.py#L11-L13

(Although the tests could be extended a bit.)

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

  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 so sánh cú pháp của Final và cách diễn đạt về việc sử dụng literal trong typing specification với PEP 591 và PEP 586. Xem xét conformance/tests/qualifiers_final_annotation.py, đặc biệt là các dòng 11-13, và mở rộng các trường hợp liên quan nếu cần. Được xem là hoàn tất khi specification nhất quán về mặt nội bộ và các conformance tests phản ánh hành vi đã được làm rõ.

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
documentation, testing-qa
Loại issue
Tài liệu
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
72/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.