`types._GeneratorWrapper` is no longer consistent with `types.GeneratorType`/`types.CoroutineType`
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.coroutine() uses _GeneratorWrapper as a wrapper for generator iterators in cases where the callable object is not a user-defined function (but is, for example, a generator function compiled via Cython/Nuitka). However, the implementation has not been updated for 11 years and therefore does not provide certain properties, such as:
GeneratorType.gi_suspended(Python ≥3.11, python/cpython#30633)CoroutineType.cr_suspended(Python ≥3.11, python/cpython#30633)CoroutineType.cr_origin(Python ≥3.7, python/cpython#5250)
As a result, the objects returned by the new function do not look exactly like types.GeneratorType/types.CoroutineType, which in particular makes them incompatible with the inspect.getgeneratorstate() and inspect.getcoroutinestate() functions:
>>> from inspect import getcoroutinestate, getgeneratorstate
>>> from types import coroutine
>>> def generator_function():
... return
... yield # generator definition
>>> @coroutine
... def coroutine_function():
... return generator_function()
>>> gencoro = coroutine_function()
>>> getgeneratorstate(gencoro)
Traceback (most recent call last):
AttributeError: '_GeneratorWrapper' object has no attribute 'gi_suspended'
>>> getcoroutinestate(gencoro)
Traceback (most recent call last):
AttributeError: '_GeneratorWrapper' object has no attribute 'cr_suspended'
Interestingly, there was already an attempt to add *_suspended in #133373 (see https://github.com/python/cpython/issues/133372#issuecomment-2849166854), but the PR was closed in favor of removing the TODO comment, and this side issue was apparently overlooked.
Related: cython/cython#7448.
CPython versions tested on:
3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux
Linked PRs
- gh-143609
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 các dòng 255-289 trong Lib/types.py, sau đó kiểm tra inspect.getgeneratorstate() và inspect.getcoroutinestate(), là những điểm đầu vào bị ảnh hưởng được báo cáo xác định. So sánh các thuộc tính được wrapper cung cấp với GeneratorType và CoroutineType; được coi là hoàn tất khi cả hai hàm inspect hoạt động với các đối tượng được bọc và các thuộc tính về trạng thái tạm dừng và nguồn gốc được liệt kê là nhất quá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
- backend
- Loại issue
- Lỗi
- Độ 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
- 28/100