C API: Add PyUnicodeWriter_WriteRawStr() function
Chưa có ai nhận issue này.
- 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ả
Feature or enhancement
Python 3.14 added PyUnicodeWriter_WriteStr() function. In general, writing str(obj) is fine. But there is one exception: writing a str subclass should not call str(obj), otherwise the output can be surprising if the subclass overrides __str__().
The _json and _io were impacted by the str subclass issue. They have been fixed by using the internal C API (_PyUnicodeWriter_WriteStr()). Problem: the internal C API is not usable outside CPython.
The PyUnicodeWriter_WriteStr() documentation has been modified to document a workaround for str subclasses:
To write a
strsubclass which overrides the__str__()method,PyUnicode_FromObject()can be used to get the original string.
Instead of the workaround, I propose adding a PyUnicodeWriter_WriteRawStr() function which handles str subclasses as expected (read the string content, don't use the __str__() method).
Linked PRs
- gh-150974
Hướng dẫn đóng góp
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.
Hướng nghiên cứu
Trước tiên, hãy xem xét PR được liên kết gh-150974, sau đó đọc tài liệu hiện có về PyUnicodeWriter_WriteStr và các tham chiếu trong _json và _io đến _PyUnicodeWriter_WriteStr. Công việc được xem là hoàn tất khi một API công khai PyUnicodeWriter_WriteRawStr() xử lý các lớp con của str mà không gọi str(), và hành vi được ghi lại trong tài liệu có thể sử dụng bên ngoài phần nội bộ của CPython.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- c, python
- Lĩnh vực
- api
- Loại issue
- Tính năng
- Độ 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
- 30/100