From 6cacb3b83b3cbb6b37987ebf7b1f2b0ed996cc91 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Tue, 12 Nov 2024 16:29:25 +0800 Subject: [PATCH 1/2] newsfragments: add 3133.bugfix.rst --- newsfragments/3133.bugfix.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 newsfragments/3133.bugfix.rst diff --git a/newsfragments/3133.bugfix.rst b/newsfragments/3133.bugfix.rst new file mode 100644 index 000000000..482d000ec --- /dev/null +++ b/newsfragments/3133.bugfix.rst @@ -0,0 +1,2 @@ +Fixed socket module for some older systems which lack `socket.AI_NUMERICSERV`. +Now trio works on legacy (pre-Lion) macOS. From 52609222075f6e595c053df524137f1d6acc6c44 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Tue, 12 Nov 2024 14:05:10 +0800 Subject: [PATCH 2/2] _socket.py: fix for systems where AI_NUMERICSERV is not defined Credits to @CoolCat467 Closes: https://github.com/python-trio/trio/issues/3133 --- src/trio/_socket.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/trio/_socket.py b/src/trio/_socket.py index ce57aab9c..59d275df5 100644 --- a/src/trio/_socket.py +++ b/src/trio/_socket.py @@ -169,7 +169,9 @@ def set_custom_socket_factory( # getaddrinfo and friends ################################################################ -_NUMERIC_ONLY = _stdlib_socket.AI_NUMERICHOST | _stdlib_socket.AI_NUMERICSERV +# AI_NUMERICSERV may be missing on some older platforms, so use it when available. +_NUMERIC_ONLY = _stdlib_socket.AI_NUMERICHOST +_NUMERIC_ONLY |= getattr(_stdlib_socket, "AI_NUMERICSERV", 0) # It would be possible to @overload the return value depending on Literal[AddressFamily.INET/6], but should probably be added in typeshed first