Improve the `help()` of type alias objects
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- developer-experience
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện đầu ra hiện tại của help(x) cho một bí danh kiểu trong REPL, sau đó lần theo cách help() xử lý các đối tượng bí danh kiểu và cách triển khai bí danh kiểu tại thời gian chạy. Công việc được xem là hoàn tất khi có thể ghi lại các chuỗi tài liệu tại thời gian chạy và help(Pair) trình bày bí danh, tài liệu của nó cùng các thuộc tính liên quan mà không mô tả gây hiểu lầm rằng bí danh là lớp TypeAliasType.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Feature or enhancement
EDIT: See https://discuss.python.org/t/runtime-docstrings-for-type-aliases/108901
Proposal:
Consider recording __doc__ on type alias objects.
For instance:
type Pair[T] = tuple[T, T]
"""A pair of values of the same type."""
Now Pair.__doc__ is "A pair of values of the same type.".
Use it in the REPL:
>>> from mymodule import Pair
>>> help(Pair)
Help on type alias Pair in module mymodule:
Pair[T] = tuple[T, T]
| A pair of values of the same type.
|
| Attributes:
|
| __value__
| Lazily evaluated value of the type alias.
|
| evaluate_value
| Evaluation function for __value__.
|
| __type_params__
| Type parameters declared by the type alias.
|
| __parameters__
| Type parameters after expansion.
|
| __name__
| Name of the type alias.
|
| __qualname__
| Qualified name of the type alias.
|
| __module__
| Module in which the type alias was defined.
(I wrote this text by hand, the actual thing could probably be improved.)
I assume IDEs/LSPs already catch it, so this is mainly a runtime feature.
Current help() just shows a slightly confusing help on the type alias type itself:
>>> type x = int
>>> help(x)
Help on TypeAliasType in module __main__ object:
x = class TypeAliasType(builtins.object)
| Type alias.
|
| Type aliases are created through the type statement::
|
...
It is confusing because (1) it reads like TypeAliasType was defined in __main__ (Help on TypeAliasType in module __main__ object), and (2) almost like if i did x = typing.TypeAliasType. (Which could be improved on its own? We could instead say x = instance of class ..., not just x = class ...)
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 558
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.
Issue khác của python/cpython
-
docs pending
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
build type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
stdlib topic-email type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Tất cả issue của python/cpython
Issue tương tự
-
link-check link-check:sphinx-theme
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100