Skip to content

Commit d3bb19b

Browse files
authored
Suppress socket imports that might not exist on some systems (#2916)
* Suppress socket imports that might not exist on some systems
1 parent e4c8eb2 commit d3bb19b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/trio/socket.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@
7070
if sys.implementation.name == "cpython":
7171
from socket import (
7272
if_indextoname as if_indextoname,
73-
if_nameindex as if_nameindex,
7473
if_nametoindex as if_nametoindex,
7574
)
7675

76+
# For android devices, if_nameindex support was introduced in API 24,
77+
# so it doesn't exist for any version prior.
78+
with _suppress(ImportError):
79+
from socket import (
80+
if_nameindex as if_nameindex,
81+
)
82+
7783

7884
# not always available so expose only if
7985
if sys.platform != "win32" or not _t.TYPE_CHECKING:

0 commit comments

Comments
 (0)