`DynamicClassAttribute` drops explicitly provided empty docstrings
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ả
Bug report
Bug description:
types.DynamicClassAttribute loses an explicitly provided empty docstring. Its constructor assigns self.__doc__ = doc or fget.__doc__, so when you pass doc='' and fget is None, the descriptor ends up with None.__doc__ (“The type of the None singleton.”) instead of retaining the empty string. This breaks parity with property, which preserves an empty doc, and cascades through setter()/deleter().
from types import DynamicClassAttribute
attr = DynamicClassAttribute(fget=None, fset=None, fdel=None, doc='')
print(repr(attr.__doc__)) # Expected '', but prints 'The type of the None singleton.'
None
Easy Fix:
class DynamicClassAttribute:
def __init__(self, fget=None, fset=None, fdel=None, doc=None):
self.fget = fget
self.fset = fset
self.fdel = fdel
- self.__doc__ = doc or fget.__doc__
- self.overwrite_doc = doc is None
+ if doc is None and fget is not None:
+ doc = fget.__doc__
+ self.__doc__ = doc
+ self.overwrite_doc = doc is None
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-140975
- gh-141242
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ừ constructor của DynamicClassAttribute trong phần triển khai types của CPython và kiểm tra cách docstring rỗng được cung cấp một cách rõ ràng được xử lý khi fget là None. Xác nhận rằng descriptor và kết quả của setter()/deleter() giữ nguyên '', phù hợp với hành vi của property, đồng thời kiểm tra các PR được liên kết để xem đã có công việc nào đang được tiến hành hay chưa.
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
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 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
- 35/100