python / python/cpython

Add `sort_dicts` parameter to `reprlib.Repr`

Đang mở
#155,812 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.

stdlib 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:

reprlib.Repr currently sorts dictionaries by key when producing representations. However, sometimes the insertion order is meaningful. It would be useful to have a sort_dicts parameter, analogous to the existing parameter in pprint.PrettyPrinter & friends.

The proposed API is:

orepr = reprlib.Repr(sort_dicts=False)
orepr.repr(my_ordered_dict)

The default should be True to preserve the existing behavior.

A possible implementation is here:
https://github.com/python/cpython/compare/main...warden127:cpython:reprlib-sort_dicts

Has this already been discussed elsewhere?

I have already opened a thread under Ideas on discuss.python.org a couple days ago, but got no response (and therefore no objections *wink*).

Links to previous discussion of this feature:
Linked PRs
  • gh-155817

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ại reprlib.Repr và xem xét hành vi sắp xếp dictionary hiện tại, sau đó so sánh API được đề xuất với pprint.PrettyPrinter. Kiểm tra PR được liên kết gh-155817; hoàn tất có nghĩa là API hỗ trợ sort_dicts=False trong khi giá trị mặc định True giữ nguyên hành vi hiện có.

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
Khá 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.