Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socketserver: Use BufferedIOBase instead of BinaryIO #12568

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Aug 21, 2024

This better matches the documentation and it also removes instances of the problematic BinaryIO semi-protocol.

@srittau srittau added the topic: io I/O related issues label Aug 21, 2024
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/platform/windows.py:98: error: Argument 1 to "read" has incompatible type "BufferedIOBase"; expected "IO[bytes]"  [arg-type]
+ mitmproxy/platform/windows.py:103: error: Argument 1 to "read" has incompatible type "BufferedIOBase"; expected "IO[bytes]"  [arg-type]
+ mitmproxy/platform/windows.py:112: error: Argument 2 to "write" has incompatible type "BufferedIOBase"; expected "IO[bytes]"  [arg-type]

@srittau
Copy link
Collaborator Author

srittau commented Aug 21, 2024

Previous use of IO[bytes] was unsafe, as IO has a name attribute, which BufferedIOBase (and socketserver._SocketWriter) does not have. Also, the impact seems to be pretty small, so well worth it in my opinion.

@JelleZijlstra JelleZijlstra merged commit 7865a78 into python:main Aug 22, 2024
63 checks passed
@srittau srittau deleted the socketserver-io branch August 22, 2024 02:34
max-muoto pushed a commit to max-muoto/typeshed that referenced this pull request Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: io I/O related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants