Skip to content

Android API 24 runtime still lacks if_indextoname and if_nametoindex #3493

Description

@FilipeMarch

Problem

Trio still fails to import on an Android CPython 3.13 runtime because socket.if_indextoname and socket.if_nametoindex are not available. The failure is:

ImportError: cannot import name 'if_indextoname' from 'socket'

The failing code is currently:

if sys.implementation.name == "cpython":
    from socket import (
        if_indextoname as if_indextoname,
        if_nametoindex as if_nametoindex,
    )

Context

This appears related to #2915 and PR #2916.

PR #2916 added ImportError suppression for if_nameindex, but the imports for if_indextoname and if_nametoindex remained unprotected, because they were believed to be available on Android. However, they are missing in the CPython Android runtime used by our application.

Environment:

  • Python: 3.13
  • Architecture: Android arm64
  • Android min API: 24
  • Android target API: 36
  • Trio: 0.33.0 and 0.34.0

A downstream workaround is:

  if sys.implementation.name == "cpython":
      with suppress(ImportError):
          from socket import (
              if_indextoname as if_indextoname,
              if_nametoindex as if_nametoindex,
          )

Expected behavior

Trio should either:

  1. suppress these optional imports as well; or
  2. explicitly document and enforce the Android runtime/API requirements needed for these functions to exist.

Since the functions are not needed by our application or by the Trio server used for TCP communication, suppressing the import appears to be the most compatible behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions