Have inspect.getdoc follow the MRO when a method docstring is only one line.
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Feature or enhancement
"Hot" on the heels of 3.5ish's https://github.com/python/cpython/issues/59787 comes another idea: An age old pattern we have in our codebase is for people to put """See base class.""" as the docstring on methods to appease lint tooling demanding a docstring on non-trivial methods. As a consequence code written this way doesn't trigger the inspect.getdoc() feature from #59787 and the help() text in a Notebook for such functions is the content-free oneliner instead of heading up the MRO chain.
I propose a new feature: If the docstring for a method exists but is <= 1 line, follow the MRO as if there were no docstring and return
f"{onelinedoc}:\n{mro_doc}" as the docstring. Do this recursively, but collapse duplicate docstrings gathered along the way so that you could wind up with [good]:
"""See base class:
Fill a hovercraft with eels of the chosen species.
Args:
species: A set of allowed Eel types.
count: float, a non-negative number of eels to add. Fractions are allowed.
"""
rather than this degenerate pattern in deep heirarchies that could otherwise result [bad]:
"""See base class:
See base class:
See base class:
Fill a hovercraft with ...
"""
Collapsing identical docstrings along the heirarchy in this case also works for the situation where they're all the same cut and pasted oneliner and nothing else.
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 entry point inspect.getdoc và các ví dụ được đề xuất trong issue. Xác định cách tra cứu MRO đệ quy cần xử lý docstring một dòng và văn bản trùng lặp, sau đó xác minh rằng tài liệu kết quả vẫn giữ dạng mở rộng mong muốn mà không có các dòng lặp lại.
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
- tooling
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- 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