Awaitable.__await__ expects a Generator where an Iterator will do
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 5.1k
- Fork
- 2.1k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 82
Mô tả
In Twisted, the Deferred class has set __await__ = __iter__, where __iter__ is typed thusly:
def __iter__(self) -> "Deferred[_DeferredResultT]":
Deferred, insofar as it has an __iter__ method, is thus itself an Iterable. It also implements __next__, so is an Iterator.
Mypy is yielding this error:
src/twisted/internet/defer.py:919:17: error: Incompatible types in assignment (expression has type "Callable[[], Deferred[_DeferredResultT]]", base class "Awaitable" defined the type as
"Callable[[], Generator[Any, None, _DeferredResultT]]") [assignment]
I suspect that perhaps Awaitable.__await__ could instead be more flexibly typed to return a Iterator[_T] instead of a Generator[Any, None, _T]… as that (a) seemingly works in this case and (b) the documentation for object.__await__ and PEP 492 say that it must return an iterator and not specifically a generator.
Deferred: mypy problem: https://github.com/python/typeshed/pull/5194#issuecomment-816339179
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 định nghĩa Awaitable liên quan đến chẩn đoán của mypy, sau đó so sánh nó với Deferred.iter và await trong src/twisted/internet/defer.py quanh các dòng 894-920. Được xem là hoàn thành khi các kiểu trả về đã khai báo chấp nhận cách triển khai iterator này mà không có lỗi gán được báo cáo, và các bước kiểm tra kiểu liên quan đều đạt.
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
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 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
- 35/100