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

Missing return value variant for socket.getaddrinfo for disable ipv6 support. #13344

Closed
MaicoTimmerman opened this issue Dec 30, 2024 · 2 comments · Fixed by #13372
Closed

Missing return value variant for socket.getaddrinfo for disable ipv6 support. #13344

MaicoTimmerman opened this issue Dec 30, 2024 · 2 comments · Fixed by #13372

Comments

@MaicoTimmerman
Copy link
Contributor

Whenever Python is compiled with --disable-ipv6, but running on a system that supports ipv6, we observe:

import socket
for info in socket.getaddrinfo("localhost", 12345, 0, socket.SOCK_STREAM):
   print(info)

resulting in:

(<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', (10, b'\x94\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'))
(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 38049))

The first type is the raw result coming from the system getaddrinfo implementation: tuple[int, int, int, str, tuple[int, bytes], currently not supported.

Now according to:

The correctness of the getaddrinfo return value is debated under the --disable-ipv6 flag. Python has marked both issues as won't fix, a long time ago.

I'm creating this issue to debate the value of adding a new return type variant to getaddrinfo. The likelihood of this happening is small, as Python usually ships with ipv6 support. However, it could result in library owners not correctly handling the return values.

@anukaal
Copy link

anukaal commented Jan 3, 2025

To resolve the issue of missing return value variants for socket.getaddrinfo when IPv6 is disabled, you need to update the socket.pyi stub file in the typeshed repository. Specifically, you should modify the return type of the getaddrinfo function to include a new variant that accounts for the scenario where IPv6 is disabled. Add a new return type variant, Tuple[int, int, int, str, Tuple[int, bytes]], to the existing return type union. This change ensures that the getaddrinfo function correctly handles the return values when IPv6 is disabled, accommodating the raw result from the system getaddrinfo implementation.

@anukaal
Copy link

anukaal commented Jan 6, 2025

great

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 a pull request may close this issue.

2 participants