python / python/cpython

`re` docs never say that the ASCII flag affects `\p{...}` properties

Đang mở
#157,698 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.

docs
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Documentation

https://docs.python.org/dev/library/re.html#re.A

The re.ASCII entry lists \w, \W, \b, \B, \d, \D, \s and \S as the constructs it restricts, and the \p{property=value} section never mentions the flags. Six accepted property spellings are restricted by the flag as well, because Nd, digit, word, space, White_Space and WSpace are matched with the same engine categories as \d, \s and \w. The other 52 accepted spellings are unaffected.

$ cat repro.py
import re
s = '0\u0663 \xa0x'
for p in 'Nd', 'digit', 'word', 'space', 'White_Space', 'WSpace':
    pat = r'\p{%s}' % p
    print('%-12s %-18r %r' % (p, re.findall(pat, s), re.findall(pat, s, re.ASCII)))

$ ./python repro.py
Nd           ['0', '٣']         ['0']
digit        ['0', '٣']         ['0']
word         ['0', '٣', 'x']    ['0', 'x']
space        [' ', '\xa0']      [' ']
White_Space  [' ', '\xa0']      [' ']
WSpace       [' ', '\xa0']      [' ']

Expected: the \p{property=value} section says which properties the ASCII flag restricts, alongside the existing note that space follows str.isspace and xdigit matches only the ASCII hexadecimal digits.

\p{White_Space} and \p{WSpace} are also absent from the documented list of supported properties, although both are accepted.

Linked PRs
  • gh-157699

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 với tài liệu về re.ASCII tại docs.python.org/dev/library/re.html#re.A, sau đó đọc phần \p{property=value} và danh sách các thuộc tính được hỗ trợ. Ghi lại sáu cách viết thuộc tính nào bị ASCII giới hạn, đồng thời thêm White_Space và WSpace vào danh sách các thuộc tính được hỗ trợ, vẫn giữ nguyên các ghi chú hiện có về space và xdigit.

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ó
1/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
30/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.