PEP 526: Name mangling doesn't take place inside the body of a module
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- reStructuredText
- Star
- 5k
- Fork
- 1.8k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 25
Mô tả
Hi,
In PEP 526, there is a section called "Runtime Effects of Type Annotations" which has the following code:
from typing import Dict
class Player:
...
players: Dict[str, Player]
__points: int
print(__annotations__)
# prints: {'players': typing.Dict[str, __main__.Player],
# '_Player__points': <class 'int'>}
The code and the output don't match.
Name mangling only happens inside the body of the class not module. So the correct output would be:
{'players': typing.Dict[str, __main__.Player], '__points': <class 'int'>}
If we want to see the effect of name mangling we could have something like:
from typing import Dict
class Player:
__points: int
players: Dict[str, Player]
print(__annotations__)
print(Player.__annotations__)
Or have the print(__annotations__) inside the class:
from typing import Dict
class Player:
__points: int
print(__annotations__)
players: Dict[str, Player]
print(__annotations__)
That would be a quick fix if you confirm.
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
Mở PEP 526 và xem lại phần “Runtime Effects of Type Annotations”, đặc biệt là ví dụ về annotation ở cấp module và output được hiển thị. Xác nhận hành vi name-mangling dựa trên ví dụ, sau đó cập nhật code hoặc output để chúng nhất quán với nhau và vẫn thể hiện rõ mangling ở cấp class. Hoàn tất khi PEP đã render không còn đưa ra các kết quả mâu thuẫn.
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
- 55/100