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

socket: constructor accepts bytes on Windows #9095

Merged
merged 2 commits into from
Nov 10, 2022

Conversation

JelleZijlstra
Copy link
Member

https://github.com/python/cpython/blob/d04899abb0da4cc7c0a390f5bc52d57ace8955fd/Modules/socketmodule.c#L5318

This is used in socket.fromshare. It must be bytes, not some other buffer.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood
Copy link
Member

It took me a while, but I finally managed to find a REPL snippet that demonstrates that this is indeed the case on my Windows machine (there might be a simpler way of demonstrating this, idk):

>>> import socket, multiprocessing
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> p = multiprocessing.Process()
>>> foo = sock.share(p._parent_pid)
>>> type(foo)
<class 'bytes'>
>>> socket.socket(fileno=foo)
<socket.socket fd=168, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>

@AlexWaygood AlexWaygood merged commit c7820b4 into python:main Nov 10, 2022
@JelleZijlstra JelleZijlstra deleted the sock branch November 10, 2022 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants