From bb228ed46b38deccf036096053e9b8b7d5ff7d21 Mon Sep 17 00:00:00 2001 From: Kumar Anirudha Date: Tue, 22 Sep 2026 01:53:27 +0530 Subject: [PATCH] Expose Bluetooth HCI socket constants on Linux `HCI_FILTER`, `HCI_TIME_STAMP` and `HCI_DATA_DIR` were only declared for platforms other than Windows, macOS and Linux, so type checkers reported them as missing on Linux even though CPython defines them there whenever it is built with Bluetooth support. The CPython docs list them as unavailable only on NetBSD, DragonFlyBSD and (for the latter two) FreeBSD. Declare them on Linux in `_socket` and `socket`, following the same pattern already used for `BTPROTO_HCI`: the `__all__` entries stay excluded on Linux and the names are added as optional entries to the Linux stubtest allowlist, because the GitHub Actions runners build Python without Bluetooth headers. --- stdlib/@tests/stubtest_allowlists/linux.txt | 3 +++ stdlib/_socket.pyi | 2 +- stdlib/socket.pyi | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/linux.txt b/stdlib/@tests/stubtest_allowlists/linux.txt index df86aeeb40a9..531e28c0f78b 100644 --- a/stdlib/@tests/stubtest_allowlists/linux.txt +++ b/stdlib/@tests/stubtest_allowlists/linux.txt @@ -90,6 +90,9 @@ select.poll # Actually a function; we have a class so it can be used as a type (_?socket\.HCI_CHANNEL_RAW)? (_?socket\.HCI_CHANNEL_USER)? (_?socket\.HCI_DEV_NONE)? +(_?socket\.HCI_DATA_DIR)? +(_?socket\.HCI_FILTER)? +(_?socket\.HCI_TIME_STAMP)? (_?socket\.L2CAP_LM)? (_?socket\.L2CAP_LM_AUTH)? (_?socket\.L2CAP_LM_ENCRYPT)? diff --git a/stdlib/_socket.pyi b/stdlib/_socket.pyi index 4450d46e6027..759fd8265387 100644 --- a/stdlib/_socket.pyi +++ b/stdlib/_socket.pyi @@ -693,7 +693,7 @@ if sys.platform != "darwin": BDADDR_ANY: Final = "00:00:00:00:00:00" BDADDR_LOCAL: Final = "00:00:00:FF:FF:FF" -if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": +if sys.platform != "win32" and sys.platform != "darwin": HCI_FILTER: Final[int] # not in NetBSD or DragonFlyBSD HCI_TIME_STAMP: Final[int] # not in FreeBSD, NetBSD, or DragonFlyBSD HCI_DATA_DIR: Final[int] # not in FreeBSD, NetBSD, or DragonFlyBSD diff --git a/stdlib/socket.pyi b/stdlib/socket.pyi index ed2873726ff1..4731aeab82c1 100644 --- a/stdlib/socket.pyi +++ b/stdlib/socket.pyi @@ -1035,9 +1035,10 @@ if sys.platform != "win32" and sys.platform != "darwin": if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": __all__ += ["BTPROTO_HCI", "BTPROTO_L2CAP", "BTPROTO_SCO"] -if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": +if sys.platform != "win32" and sys.platform != "darwin": from _socket import HCI_DATA_DIR as HCI_DATA_DIR, HCI_FILTER as HCI_FILTER, HCI_TIME_STAMP as HCI_TIME_STAMP +if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": __all__ += ["HCI_FILTER", "HCI_TIME_STAMP", "HCI_DATA_DIR"] if sys.version_info >= (3, 11) and sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin":