python / python/cpython

Better `repr` for `string.templatelib.Template`.

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

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

interpreter-core type-feature
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

Proposal:

Currently the repr output for template strings shows how the data is stored internally, but this is not how the template could be reconstructed via an constructor call and the format is unintuitive since the template parts are not output in the order they appear in the template source. The repr result should output the parts in the order as iterating over the template object does, i.e.

x = 1
y = 2
print(repr(t'{x} + {y}'))

should print

Template(Interpolation(1, 'x', None, ''), ' + ', Interpolation(2, 'y', None, ''))

instead of

Template(strings=('', ' + ', ''), interpolations=(Interpolation(1, 'x', None, ''), Interpolation(2, 'y', None, '')))

This has already been discussed at https://discuss.python.org/t/repr-output-of-t-strings/107653

I'm working on a patch/pull request.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/repr-output-of-t-strings/107653

Linked PRs
  • gh-151104

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 từ hành vi repr của string.templatelib.Template được mô tả trong issue và so sánh với việc lặp qua một đối tượng Template. Xác minh rằng repr xuất các phần Template theo thứ tự lặp và khớp với định dạng lời gọi constructor được đề xuất; gh-151104 được liên kết, vì vậy hãy xem xét công việc đó trước khi bắt đầu.

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
backend
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
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
25/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.