ConfigParser.items() docstring does not describe the no-argument overload
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 docstring of configparser.ConfigParser.items at Lib/configparser.py:887-897 describes only the call with a section argument:
def items(self, section=_UNSET, raw=False, vars=None):
"""Return a list of (name, value) tuples for each option in a section.
All % interpolations are expanded in the return values, based on the
defaults passed into the constructor, unless the optional argument
`raw` is true. Additional substitutions may be provided using the
`vars` argument, which must be a dictionary whose contents overrides
any pre-existing defaults.
The section DEFAULT is special.
"""
if section is _UNSET:
return super().items()
...
return [(option, value_getter(option)) for option in orig_keys]
When called with no arguments, items() delegates to the items() method inherited from collections.abc.Mapping and returns a collections.abc.ItemsView of (section_name, section_proxy) pairs — not a list of (name, value) tuples. The docstring currently mentions neither this overload nor its return type.
This is a follow-up to gh-149050 / gh-150059, which fixed the same kind of mismatch in Doc/library/configparser.rst. StanFromIreland reviewed that PR, while picnixz discussed the behavior on the issue. The .rst change remained scoped to the library documentation, so the docstring was left unchanged and is tracked here.
Suggested fix
Reword the docstring so that both overloads are described, e.g.:
"""Return the items of the parser or of a section.
When *section* is not given, return an :class:`~collections.abc.ItemsView`
of `(section_name, section_proxy)` pairs, including `DEFAULTSECT`.
Otherwise, return a list of `(name, value)` tuples for each option in the
given section. All % interpolations are expanded in the return values,
based on the defaults passed into the constructor, unless the optional
argument `raw` is true. Additional substitutions may be provided using
the `vars` argument, which must be a dictionary whose contents overrides
any pre-existing defaults.
The section DEFAULT is special.
"""
(bpo-15803 / gh-60007 corrected the module-level API summary in 2012. The no-argument overload itself was added in 2010, but this method docstring continued to describe only the section-argument form.)
Linked PRs
- gh-150133
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 tại Lib/configparser.py:887-897 và so sánh ConfigParser.items() với hành vi của Mapping.items() được kế thừa. Kiểm tra phần theo dõi tài liệu được liên kết và gh-150133 trước khi thực hiện thay đổi. Được xem là hoàn tất khi docstring mô tả chính xác cả dạng ItemsView không có đối số lẫn dạng danh sách có đối số section.
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
- Dưới một 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
- 25/100