"typing.BinaryIO" missing "readinto" method
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:
typeing.BinaryIO is completely missing the readinto method. All binary mode return values of open support the readinto method, and the lack of it on the BinaryIO type makes type-hinting difficult when using this method. One could try to use io.RawIOBase | io.BufferedIOBase but this looses the fact that the result of open has a name property. This has been brought up in python/typing#659 and python/typeshed#2166.
Furthmore, the write method in BinaryIO is declared to only be compatible with Union[bytes, bytearray] when it should be anything that satisfies collections.abc.Buffer.
I propose that BinaryIO should look something more like:
class BinaryIO(IO[bytes]):
"""Typed version of the return of open() in binary mode."""
__slots__ = ()
@abstractmethod
def readinto(self, b: collections.abc.Buffer) -> int:
pass
@abstractmethod
def write(self, s: collections.abc.Buffer) -> int:
pass
@abstractmethod
def __enter__(self) -> 'BinaryIO':
pass
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
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 từ định nghĩa typing.BinaryIO và so sánh nó với các giá trị trả về của open() ở chế độ nhị phân, tập trung vào các chữ ký readinto và write tương thích với Buffer được đề xuất. Xác minh rằng BinaryIO vẫn cung cấp thuộc tính name và hành vi typing được cập nhật đã được các bài kiểm thử hiện có liên quan bao phủ; issue không nêu tên tệp hoặc bài kiểm thử cụ thể nào.
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
- developer-experience
- 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
- 45/100