Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
61b540f
socket : add python 3.14 bluetooth constants for windows and linux
Divyanshudevtalla Jan 27, 2026
f460d10
socket: add Python 3.14 bluetooth constant with version guards
Divyanshudevtalla Jan 27, 2026
541eb42
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 27, 2026
8875184
address review: move constants to semi-documented and add allowlist …
Divyanshudevtalla Jan 28, 2026
83ca700
address review : move constants to semi-documented and fix version gu…
Divyanshudevtalla Jan 28, 2026
d8ee6b5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 28, 2026
717f7cb
fix: resolve merge conflict and update allowlist
Divyanshudevtalla Jan 28, 2026
74c8f48
fix: resolve sync issue and finalize allowlist
Divyanshudevtalla Jan 28, 2026
3efa725
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 28, 2026
b9f25b7
fix : resolve all CI faillures by updating socket.pyi and cleaning ma…
Divyanshudevtalla Jan 28, 2026
78ddaf3
fix: sync with remote and finalize socket constants
Divyanshudevtalla Jan 28, 2026
096518f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 28, 2026
e5a8806
refactor: remove duplicates,sort alphabatecally, and update allowlist
Divyanshudevtalla Jan 28, 2026
ac8ecb8
Merge branch 'add-bluetooth-constants' of https://github.com/Divyansh…
Divyanshudevtalla Jan 28, 2026
f2eb6ac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 28, 2026
16415a6
Fix : add missing runtime constants to linux-py314 allowlist
Divyanshudevtalla Jan 29, 2026
a987b39
Fix: add platform-specific allowlists and remove reduntant entries
Divyanshudevtalla Jan 29, 2026
d73e6e7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2026
a7e5293
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2026
b1a62e3
fix : remaining fails fix
Divyanshudevtalla Jan 29, 2026
457e7fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2026
e0056ab
Fix : update plateform allowlist
Divyanshudevtalla Jan 29, 2026
db48b40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2026
e8bff12
updating fixes
Divyanshudevtalla Jan 29, 2026
7827112
fix updating
Divyanshudevtalla Jan 29, 2026
4cf8971
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2026
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
7 changes: 7 additions & 0 deletions stdlib/@tests/stubtest_allowlists/darwin-py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ _msi
msilib(.[a-z]+)?
ossaudiodev
spwd

# Bluetooth constants added for Python 3.14+ but missing at runtime on Windows test runners
_socket.SO_BTH_ENCRYPT
_socket.SO_BTH_MTU
_socket.SO_BTH_MTU_MAX
_socket.SO_BTH_MTU_MIN
_socket.SOL_RFCOMM
7 changes: 7 additions & 0 deletions stdlib/@tests/stubtest_allowlists/darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ tkinter.Tk.deletefilehandler # Methods that come from __getattr__() at runtime
(_?locale.dgettext)?
(_?locale.gettext)?
(_?locale.textdomain)?

# Bluetooth constants added for Python 3.14+ but missing at runtime on Windows test runners
_socket.SO_BTH_ENCRYPT
_socket.SO_BTH_MTU
_socket.SO_BTH_MTU_MAX
_socket.SO_BTH_MTU_MIN
_socket.SOL_RFCOMM
5 changes: 5 additions & 0 deletions stdlib/@tests/stubtest_allowlists/linux-py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ msilib(.[a-z]+)?

# doesn't exist in all installations
(nis)?

# Bluetooth constants added for Python 3.14+ but missing at runtime on Ubuntu test runners

_socket.HCI_CHANNEL_RAW
_socket.SOL_RFCOMM
8 changes: 8 additions & 0 deletions stdlib/@tests/stubtest_allowlists/linux-py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
# Starting with Python 3.14.1, these methods accept None for some of their
# parameters, but would raise a TypeError with Python 3.14.0.
mmap.mmap.madvise

# Bluetooth constants new in 3.14 but missing at runtime on Ubuntu test runners
_socket.BT_MODE_STREAM
_socket.BT_PHY_LE_2M_RX
_socket.BT_SCM_PKT_STATUS
_socket.BT_VOICE_FOR_MSBC
_socket.HCI_CHANNEL_RAW
_socket.SOL_RFCOMM
70 changes: 69 additions & 1 deletion stdlib/@tests/stubtest_allowlists/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,70 @@ select.poll # Actually a function; we have a class so it can be used as a type
(_?socket\.BTPROTO_L2CAP)?
(_?socket\.BTPROTO_RFCOMM)?
(_?socket\.BTPROTO_SCO)?

(_?socket\.BDADDR_BREDR)?
(_?socket\.BDADDR_LE_PUBLIC)?
(_?socket\.BDADDR_LE_RANDOM)?
(_?socket\.BT_CHANNEL_POLICY)?
(_?socket\.BT_CHANNEL_POLICY_BREDR_ONLY)?
(_?socket\.BT_CHANNEL_POLICY_BREDR_PREFERRED)?
(_?socket\.BT_CODEC)?
(_?socket\.BT_DEFER_SETUP)?
(_?socket\.BT_FLUSHABLE)?
(_?socket\.BT_FLUSHABLE_OFF)?
(_?socket\.BT_FLUSHABLE_ON)?
(_?socket\.BT_ISO_QOS)?
(_?socket\.BT_MODE)?
(_?socket\.BT_MODE_BASIC)?
(_?socket\.BT_MODE_ERTM)?
(_?socket\.BT_MODE_EXT_FLOWCTL)?
(_?socket\.BT_MODE_LE_FLOWCTL)?
(_?socket\.BT_MODE_STREAMING)?
(_?socket\.BT_PHY)?
(_?socket\.BT_PHY_BR_1M_1SLOT)?
(_?socket\.BT_PHY_BR_1M_3SLOT)?
(_?socket\.BT_PHY_BR_1M_5SLOT)?
(_?socket\.BT_PHY_EDR_2M_1SLOT)?
(_?socket\.BT_PHY_EDR_2M_3SLOT)?
(_?socket\.BT_PHY_EDR_2M_5SLOT)?
(_?socket\.BT_PHY_EDR_3M_1SLOT)?
(_?socket\.BT_PHY_EDR_3M_3SLOT)?
(_?socket\.BT_PHY_EDR_3M_5SLOT)?
(_?socket\.BT_PHY_LE_1M_RX)?
(_?socket\.BT_PHY_LE_1M_TX)?
(_?socket\.BT_PHY_LE_2M_TX)?
(_?socket\.BT_PHY_LE_CODED_RX)?
(_?socket\.BT_PHY_LE_CODED_TX)?
(_?socket\.BT_PKT_STATUS)?
(_?socket\.BT_POWER)?
(_?socket\.BT_POWER_FORCE_ACTIVE_OFF)?
(_?socket\.BT_POWER_FORCE_ACTIVE_ON)?
(_?socket\.BT_RCVMTU)?
(_?socket\.BT_SECURITY)?
(_?socket\.BT_SECURITY_FIPS)?
(_?socket\.BT_SECURITY_HIGH)?
(_?socket\.BT_SECURITY_LOW)?
(_?socket\.BT_SECURITY_MEDIUM)?
(_?socket\.BT_SECURITY_SDP)?
(_?socket\.BT_SNDMTU)?
(_?socket\.BT_VOICE)?
(_?socket\.BT_VOICE_CVSD_16BIT)?
(_?socket\.BT_VOICE_TRANSPARENT)?
(_?socket\.BT_VOICE_TRANSPARENT_16BIT)?
(_?socket\.HCI_CHANNEL_CONTROL)?
(_?socket\.HCI_CHANNEL_LOGGING)?
(_?socket\.HCI_CHANNEL_MONITOR)?
(_?socket\.HCI_CHANNEL_USER)?
(_?socket\.HCI_DEV_NONE)?
(_?socket\.L2CAP_LM)?
(_?socket\.L2CAP_LM_AUTH)?
(_?socket\.L2CAP_LM_ENCRYPT)?
(_?socket\.L2CAP_LM_MASTER)?
(_?socket\.L2CAP_LM_RELIABLE)?
(_?socket\.L2CAP_LM_SECURE)?
(_?socket\.L2CAP_LM_TRUSTED)?
(_?socket\.SOL_BLUETOOTH)?
(_?socket\.SOL_L2CAP)?
(_?socket\.SOL_SCO)?
# These seem like they should be available on Linux, but they're not
# on GitHub Actions runners for some reason.
_?socket.IPX_TYPE
Expand Down Expand Up @@ -69,3 +132,8 @@ termios.TIOCTTYGSTRUCT

tkinter.Tk.createfilehandler # Methods that come from __getattr__() at runtime
tkinter.Tk.deletefilehandler # Methods that come from __getattr__() at runtime

# Bluetooth constants added for Python 3.14+ but missing at runtime on Ubuntu test runners

_socket.HCI_CHANNEL_RAW
_socket.SOL_RFCOMM
7 changes: 7 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,10 @@ _pickle.Pickler.persistent_id
_pickle.Unpickler.persistent_load
pickle.Pickler.persistent_id
pickle.Unpickler.persistent_load

# Bluetooth constants added for Python 3.14+ but missing at runtime on Windows test runners
_socket.SO_BTH_ENCRYPT
_socket.SO_BTH_MTU
_socket.SO_BTH_MTU_MAX
_socket.SO_BTH_MTU_MIN
_socket.SOL_RFCOMM
7 changes: 7 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,10 @@ builtins.property.__set_name__ # Doesn't actually exist
collections\.UserList\.index # ignoring pos-or-keyword parameter
dataclasses.KW_ONLY # white lies around defaults
importlib.metadata._meta.SimplePath.joinpath # Runtime definition of protocol is incorrect

# Bluetooth constants added for Python 3.14+ but missing at runtime on Windows test runners
_socket.SO_BTH_ENCRYPT
_socket.SO_BTH_MTU
_socket.SO_BTH_MTU_MAX
_socket.SO_BTH_MTU_MIN
_socket.SOL_RFCOMM
7 changes: 7 additions & 0 deletions stdlib/@tests/stubtest_allowlists/win32-py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ crypt
nis
ossaudiodev
spwd

# Bluetooth constants added for Python 3.14+ but missing at runtime on Windows test runners
_socket.SO_BTH_ENCRYPT
_socket.SO_BTH_MTU
_socket.SO_BTH_MTU_MAX
_socket.SO_BTH_MTU_MIN
_socket.SOL_RFCOMM
7 changes: 7 additions & 0 deletions stdlib/@tests/stubtest_allowlists/win32-py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ crypt
nis
ossaudiodev
spwd

# Bluetooth constants added for Python 3.14+ but missing at runtime on Windows test runners
_socket.SO_BTH_ENCRYPT
_socket.SO_BTH_MTU
_socket.SO_BTH_MTU_MAX
_socket.SO_BTH_MTU_MIN
_socket.SOL_RFCOMM
7 changes: 7 additions & 0 deletions stdlib/@tests/stubtest_allowlists/win32-py313.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
# (Hard to add types for unless we add stubs for the undocumented _overlapped module...)
asyncio.IocpProactor.finish_socket_func
asyncio.windows_events.IocpProactor.finish_socket_func

# Bluetooth constants added for Python 3.14+ but missing at runtime on Windows test runners
_socket.SO_BTH_ENCRYPT
_socket.SO_BTH_MTU
_socket.SO_BTH_MTU_MAX
_socket.SO_BTH_MTU_MIN
_socket.SOL_RFCOMM
7 changes: 7 additions & 0 deletions stdlib/@tests/stubtest_allowlists/win32-py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
# (Hard to add types for unless we add stubs for the undocumented _overlapped module...)
asyncio.IocpProactor.finish_socket_func
asyncio.windows_events.IocpProactor.finish_socket_func

# Bluetooth constants added for Python 3.14+ but missing at runtime on Windows test runners
_socket.SO_BTH_ENCRYPT
_socket.SO_BTH_MTU
_socket.SO_BTH_MTU_MAX
_socket.SO_BTH_MTU_MIN
_socket.SOL_RFCOMM
7 changes: 7 additions & 0 deletions stdlib/@tests/stubtest_allowlists/win32.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ tty
multiprocessing.popen_fork # exists on Windows but fails to import
multiprocessing.popen_forkserver # exists on Windows but fails to import
multiprocessing.popen_spawn_posix # exists on Windows but fails to import

# Bluetooth constants added for Python 3.14+ but missing at runtime on Windows test runners
_socket.SO_BTH_ENCRYPT
_socket.SO_BTH_MTU
_socket.SO_BTH_MTU_MAX
_socket.SO_BTH_MTU_MIN
_socket.SOL_RFCOMM
91 changes: 82 additions & 9 deletions stdlib/_socket.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ _CMSGArg: TypeAlias = tuple[int, int, ReadableBuffer]
# Addresses can be either tuples of varying lengths (AF_INET, AF_INET6,
# AF_NETLINK, AF_TIPC) or strings/buffers (AF_UNIX).
# See getsockaddrarg() in socketmodule.c.
_Address: TypeAlias = tuple[Any, ...] | str | ReadableBuffer
_Address: TypeAlias = tuple[Any, ...] | str | ReadableBuffer | int
# int is included because of device_id not packed in a tuple is now accepted for BTPROTO_HCI
_RetAddress: TypeAlias = Any

# ===== Constants =====
Expand Down Expand Up @@ -76,6 +77,11 @@ if sys.platform != "linux":
SO_USELOOPBACK: Final[int]
if sys.platform == "win32":
SO_EXCLUSIVEADDRUSE: Final[int]
SO_BTH_ENCRYPT: Final[int]
SO_BTH_MTU: Final[int]
SO_BTH_MTU_MAX: Final[int]
SO_BTH_MTU_MIN: Final[int]
SOL_RFCOMM: Final[int]
if sys.platform != "win32":
SO_REUSEPORT: Final[int]
if sys.platform != "darwin" or sys.version_info >= (3, 13):
Expand Down Expand Up @@ -240,11 +246,6 @@ if sys.version_info >= (3, 14):
SO_ORIGINAL_DST: Final[int]

if sys.platform == "win32":
SOL_RFCOMM: Final[int]
SO_BTH_ENCRYPT: Final[int]
SO_BTH_MTU: Final[int]
SO_BTH_MTU_MAX: Final[int]
SO_BTH_MTU_MIN: Final[int]
TCP_QUICKACK: Final[int]

if sys.platform == "linux":
Expand Down Expand Up @@ -579,7 +580,47 @@ if sys.platform == "linux":
SO_VM_SOCKETS_BUFFER_SIZE: Final = 0
SO_VM_SOCKETS_BUFFER_MIN_SIZE: Final = 1
VM_SOCKETS_INVALID_VERSION: Final = 0xFFFFFFFF # undocumented

# Bluetooth constants new in 3.14
if sys.version_info >= (3, 14):
BDADDR_BREDR: int
BDADDR_LE_PUBLIC: int
BDADDR_LE_RANDOM: int
BT_CHANNEL_POLICY_BREDR_ONLY: int
BT_CHANNEL_POLICY_BREDR_PREFERRED: int
BT_CHANNEL_POLICY: int
BT_CODEC: int
BT_DEFER_SETUP: int
BT_FLUSHABLE_OFF: int
BT_FLUSHABLE_ON: int
BT_FLUSHABLE: int
BT_ISO_QOS: int
BT_MODE_BASIC: int
BT_MODE_ERTM: int
BT_MODE_STREAM: int
BT_MODE: int
BT_PHY_BR_1M_1SLOT: int
BT_PHY_EDR_2M_1SLOT: int
BT_PHY_EDR_2M_3SLOT: int
BT_PHY_EDR_2M_5SLOT: int
BT_PHY_EDR_3M_1SLOT: int
BT_PHY_EDR_3M_3SLOT: int
BT_PHY_EDR_3M_5SLOT: int
BT_PHY_LE_1M_RX: int
BT_PHY_LE_1M_TX: int
BT_PHY_LE_2M_RX: int
BT_PHY_LE_2M_TX: int
BT_PHY_LE_CODED_RX: int
BT_PHY_LE_CODED_TX: int
BT_PHY: int
BT_PKT_STATUS: int
BT_POWER_FORCE_ACTIVE_OFF: int
BT_POWER_FORCE_ACTIVE_ON: int
BT_POWER: int
BT_RCVMTU: int
BT_SCM_PKT_STATUS: int
BT_SNDMTU: int
BT_VOICE_FOR_MSBC: int
BT_VOICE: int
# Documented as only available on BSD, macOS, but empirically sometimes
# available on Windows
if sys.platform != "linux":
Expand Down Expand Up @@ -630,9 +671,41 @@ if sys.version_info >= (3, 12):
ETHERTYPE_IP: Final[int]
ETHERTYPE_IPV6: Final[int]
ETHERTYPE_VLAN: Final[int]
# --------------------
# Semi-documented constants

BT_MODE_EXT_FLOWCTL: Final[int]
BT_MODE_LE_FLOWCTL: Final[int]
BT_MODE_STREAMING: Final[int]
BT_PHY_BR_1M_3SLOT: Final[int]
BT_PHY_BR_1M_5SLOT: Final[int]
BT_SECURITY_FIPS: Final[int]
BT_SECURITY_HIGH: Final[int]
BT_SECURITY_LOW: Final[int]
BT_SECURITY_MEDIUM: Final[int]
BT_SECURITY_SDP: Final[int]
BT_SECURITY: Final[int]
BT_VOICE_CVSD_16BIT: Final[int]
BT_VOICE_TRANSPARENT_16BIT: Final[int]
BT_VOICE_TRANSPARENT: Final[int]
HCI_CHANNEL_CONTROL: Final[int]
HCI_CHANNEL_LOGGING: Final[int]
HCI_CHANNEL_MONITOR: Final[int]
HCI_CHANNEL_RAW: Final[int]
HCI_CHANNEL_USER: Final[int]
HCI_DEV_NONE: Final[int]
L2CAP_LM_AUTH: Final[int]
L2CAP_LM_ENCRYPT: Final[int]
L2CAP_LM_MASTER: Final[int]
L2CAP_LM_RELIABLE: Final[int]
L2CAP_LM_SECURE: Final[int]
L2CAP_LM_TRUSTED: Final[int]
L2CAP_LM: Final[int]
SOL_BLUETOOTH: Final[int]
SOL_L2CAP: Final[int]
SOL_RFCOMM: Final[int]
SOL_SCO: Final[int]

# --------------------
# Semi-documented constants
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't move this comment. Instead the new Bluetooth constants should be added somewhere below here.

# These are alluded to under the "Socket families" section in the docs
# https://docs.python.org/3/library/socket.html#socket-families
# --------------------
Expand Down
Loading