Skip to content

Commit d6c4cae

Browse files
authored
Merge pull request #3135 from barracuda156/AI_NUMERICSERV
_socket.py: fix for systems where AI_NUMERICSERV is not defined
2 parents 67f7455 + a821d36 commit d6c4cae

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

newsfragments/3133.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed socket module for some older systems which lack ``socket.AI_NUMERICSERV``.
2+
Now trio works on legacy (pre-Lion) macOS.

src/trio/_socket.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ def set_custom_socket_factory(
164164
# getaddrinfo and friends
165165
################################################################
166166

167-
_NUMERIC_ONLY = _stdlib_socket.AI_NUMERICHOST | _stdlib_socket.AI_NUMERICSERV
167+
# AI_NUMERICSERV may be missing on some older platforms, so use it when available.
168+
# See: https://github.com/python-trio/trio/issues/3133
169+
_NUMERIC_ONLY = _stdlib_socket.AI_NUMERICHOST
170+
_NUMERIC_ONLY |= getattr(_stdlib_socket, "AI_NUMERICSERV", 0)
168171

169172

170173
# It would be possible to @overload the return value depending on Literal[AddressFamily.INET/6], but should probably be added in typeshed first

0 commit comments

Comments
 (0)