From 71e7154264b887a1c8e58ec9789074026baffaeb Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Tue, 2 Jan 2024 13:04:54 -0600 Subject: [PATCH 1/3] Suppress socket imports that might not exist on some systems --- src/trio/socket.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/trio/socket.py b/src/trio/socket.py index 8e2e24aafd..9c15a110fd 100644 --- a/src/trio/socket.py +++ b/src/trio/socket.py @@ -68,11 +68,14 @@ ) if sys.implementation.name == "cpython": - from socket import ( - if_indextoname as if_indextoname, - if_nameindex as if_nameindex, - if_nametoindex as if_nametoindex, - ) + # Apparently, these functions aren't available on Android with + # API < 24 (and possibly other platforms) + with _suppress(ImportError): + from socket import ( + if_indextoname as if_indextoname, + if_nameindex as if_nameindex, + if_nametoindex as if_nametoindex, + ) # not always available so expose only if From a435dd147a649822603b2fc044f61870bf33b206 Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:36:30 -0600 Subject: [PATCH 2/3] Only suppress `if_nameindex` import and add better comment for the future --- src/trio/socket.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/trio/socket.py b/src/trio/socket.py index 9c15a110fd..e0880c622d 100644 --- a/src/trio/socket.py +++ b/src/trio/socket.py @@ -68,13 +68,17 @@ ) if sys.implementation.name == "cpython": - # Apparently, these functions aren't available on Android with - # API < 24 (and possibly other platforms) + from socket import ( + if_indextoname as if_indextoname, + if_nametoindex as if_nametoindex, + ) + + # In https://github.com/kivy/python-for-android, if_nameindex + # was introduced in API 24, so it doesn't exist for any version + # prior. with _suppress(ImportError): from socket import ( - if_indextoname as if_indextoname, if_nameindex as if_nameindex, - if_nametoindex as if_nametoindex, ) From 9dda073c330ccd6658ab0d022ef645fca9365c1e Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Thu, 11 Jan 2024 00:03:46 -0600 Subject: [PATCH 3/3] Reword comment --- src/trio/socket.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/trio/socket.py b/src/trio/socket.py index e0880c622d..00eb98c092 100644 --- a/src/trio/socket.py +++ b/src/trio/socket.py @@ -73,9 +73,8 @@ if_nametoindex as if_nametoindex, ) - # In https://github.com/kivy/python-for-android, if_nameindex - # was introduced in API 24, so it doesn't exist for any version - # prior. + # For android devices, if_nameindex support was introduced in API 24, + # so it doesn't exist for any version prior. with _suppress(ImportError): from socket import ( if_nameindex as if_nameindex,