python / python/typing

[spec] clarification or change of "`partial\n` in a `py.typed` file"

Đang mở
#2,113 0 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: 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ả

Reading through https://typing.python.org/en/latest/spec/distributing.html#partial-stub-packages today for unrelated purposes, it struck me that the occurrences of partial\n are ambiguous because it could be interpreted as requiring literally a backslash and an n. Furthermore, assuming \n is actually not to be taken literally (which is reasonable given that other places in the spec use glob stars anyway, although never in something you actually type into a file) it's ambiguous what happens if you use CRLF or CR as line terminators in your file. This also seems to rule out a file that just contains partial and then ends, without a newline character (you're not "supposed to" do this, but it happens).

To keep exactly the current behavior, I think this verbiage should be tweaked to "partial, followed by a newline". Perhaps the linefeed and carriage return characters could be mentioned explicitly, or a mention can be made of universal newlines.

However, I am not sure if the current behavior is actually important to specify, and I think other possibilities make more sense. Other possibilities include "partial on a line by itself", "partial surrounded by any amount of whitespace", and just "partial". "As the sole content of the file" may be added if desired.

A brief survey suggests that:

  • mypy does fscache.read(stub_typed_file).decode().strip() == "partial", which is not quite the same as the specified check
  • pyright does (pyTypedContents.match(/partial\n/) || pyTypedContents.match(/partial\r\n/)), which is certainly a reasonable interpretation of the current spec, especially if you assume that no one ever uses only-CR newlines
  • ty does to_ascii_lowercase().contains("partial") to be deliberately permissive, as explained in a comment

There is a reasonably long discussion about this topic over at https://discuss.python.org/t/pep-561-clarification-regarding-n/32875, but I didn't find it very enlightening.

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 đọc phần về các gói stub một phần trong distributing.html, sau đó so sánh các kiểm tra được liên kết của mypy, pyright và ty cùng với chuỗi thảo luận được tham chiếu trên discuss.python.org. Công việc được hoàn thành khi đã thống nhất về quy tắc khớp dự kiến và cập nhật đặc tả để nêu quy tắc đó một cách không mơ hồ, bao gồm cả hành vi đối với ký tự xuống dòng và cuối tệp.

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
Loại issue
Tài liệu
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
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.