Defaultdict docs could be clearer
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ả
Documentation
The first three paragraphs of the current defaultdict class docs currently read:
Return a new dictionary-like object. defaultdict is a subclass of the built-in dict class. It overrides one method and adds one writable instance variable. The remaining functionality is the same as for the dict class and is not documented here.
The first argument provides the initial value for the default_factory attribute; it defaults to None. All remaining arguments are treated the same as if they were passed to the dict constructor, including keyword arguments.
defaultdicts are generic over two types, signifying (respectively) the types of the dictionary’s keys and values.
Nowhere in this do we learn about what the defaultdict does differently from dict. We don't even learn what the default_factory parameter is. In fact, the description of the default_factory attribute is decidedly uninformative as well:
This attribute is used by the missing() method; it is initialized from the first argument to the constructor, if present, or to None, if absent.
Basically, I need to read the documentation of the dunder method __missing__ to learn what imo should be stated somewhere at the top earlier.
Suggestions:
- Have a few beginner-friendly introductory sentences that explain in plain language what defaultdict is / how its behaviour differs from dict.
For example, the first sentence of the namedtuple section is
"Named tuples assign meaning to each position in a tuple and allow for more readable, self-documenting code." The utility / motivation for defaultdict is explained well in the Examples section so that doesn't need to be stated (and it feels hard to state its utility without examples).
- Expand the
default_factoryattribute documentation so it is more standalone. At the very least it should state that it should be a callable? The fact that thedefault_factoryparameter must be a callable (or None) should also be stated up top, since the code otherwise throws a TypeError.
Some previous discussions: #131490, #85787 #53745
Happy to try a PR. :-)
Linked PRs
- gh-157033
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
Bắt đầu với tài liệu hiện tại của lớp defaultdict được liên kết trong issue và so sánh các đoạn mở đầu cùng phần mô tả thuộc tính default_factory với những cải tiến được yêu cầu. Công việc được xem là hoàn tất khi tài liệu giải thích sự khác biệt giữa defaultdict và dict, mô tả default_factory là một callable hoặc None, đồng thời cung cấp phần giải thích độc lập mà không yêu cầu người đọc bắt đầu từ missing().
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ó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- 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