Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/3493.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid erroring when running in a CPython built for an Android API version less than 24.
18 changes: 13 additions & 5 deletions src/trio/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,18 @@
)

if sys.implementation.name == "cpython":
from socket import (
if_indextoname as if_indextoname,
if_nametoindex as if_nametoindex,
)
if sys.version_info >= (3, 16): # pragma: no branch
from socket import ( # pragma: no cover
if_indextoname as if_indextoname,
if_nametoindex as if_nametoindex,
)
else:
# https://github.com/python/cpython/issues/156439
with _suppress(ImportError):
from socket import (
if_indextoname as if_indextoname,
if_nametoindex as if_nametoindex,
)

# For android devices, if_nameindex support was introduced in API 24,
# so it doesn't exist for any version prior.
Expand All @@ -82,7 +90,7 @@
)


# not always available so expose only if
# not always available so expose only if possible
if sys.platform != "win32" or not _t.TYPE_CHECKING:
with _suppress(ImportError):
from socket import (
Expand Down