dis: FOR_ITER says it no longer pops the stack in 3.12 but it still does when the iterator ended normally
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 FOR_ITER docs in the dis module say "Up until 3.11 the iterator was popped when it was exhausted". This sounds like in 3.12+ the iterator is not popped anymore:
Instead there is a new opcode END_FOR, which takes care of popping the iterator off the stack. This surprised me because in 3.12 END_FOR is supposed to remove 2 elements from the top of the stack. But if the iterator ends normally, there will only be the iterator at the top. I tried to document my thought process in this godbolt repro.
Reading the generated code for FOR_ITER, specifically:
it looks like there are 2 cases:
- If the iterator ends normally,
FOR_ITERpops the iterator off the stack, then it skips the nextEND_FOR(and in 3.13POP_TOP) instructions. - Otherwise (I'm not sure when that happens?), the iterator ends with both the
iteranditer()on the stack, which are both popped byEND_FOR(and in 3.13POP_TOP).
Is it worth documenting the 2 different cases?
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 phần mô tả FOR_ITER trong Doc/library/dis.rst và so sánh với các trường hợp FOR_ITER và END_FOR trong Python/generated_cases.c.h được issue dẫn chiếu. Xác minh các đường đi thông thường và thay thế khi iterator cạn trong Python 3.12 và 3.13, sau đó cập nhật tài liệu nếu cả hai hành vi của stack đều được xác nhận và có thể giải thích rõ ràng.
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
- compilers, documentation
- Loại issue
- Tài liệu
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- 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
- 48/100