Skip to content

Commit b7f8d84

Browse files
authored
socket: consistency between constants and enums (#8099)
This matches what happens at runtime, from Enum._convert_ Helps with #8098. Closes #5696.
1 parent 64181e8 commit b7f8d84

File tree

9 files changed

+33
-32
lines changed

9 files changed

+33
-32
lines changed

stdlib/socket.pyi

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -390,39 +390,43 @@ class AddressFamily(IntEnum):
390390
AF_INET: int
391391
AF_INET6: int
392392
AF_AAL5: int
393-
AF_ALG: int
394393
AF_APPLETALK: int
395394
AF_ASH: int
396395
AF_ATMPVC: int
397396
AF_ATMSVC: int
398397
AF_AX25: int
399-
AF_BLUETOOTH: int
400398
AF_BRIDGE: int
401-
AF_CAN: int
402399
AF_DECnet: int
403400
AF_ECONET: int
404401
AF_IPX: int
405402
AF_IRDA: int
406403
AF_KEY: int
407-
AF_LINK: int
408404
AF_LLC: int
409405
AF_NETBEUI: int
410-
AF_NETLINK: int
411406
AF_NETROM: int
412-
AF_PACKET: int
413407
AF_PPPOX: int
414-
AF_QIPCRTR: int
415-
AF_RDS: int
416408
AF_ROSE: int
417409
AF_ROUTE: int
418410
AF_SECURITY: int
419411
AF_SNA: int
420412
AF_SYSTEM: int
421-
AF_TIPC: int
422413
AF_UNSPEC: int
423-
AF_VSOCK: int
424414
AF_WANPIPE: int
425415
AF_X25: int
416+
if sys.platform == "linux":
417+
AF_CAN: int
418+
AF_PACKET: int
419+
AF_RDS: int
420+
AF_TIPC: int
421+
AF_ALG: int
422+
AF_NETLINK: int
423+
if sys.version_info >= (3, 7):
424+
AF_VSOCK: int
425+
if sys.version_info >= (3, 8):
426+
AF_QIPCRTR: int
427+
AF_LINK: AddressFamily # availability: BSD, macOS
428+
if sys.platform != "darwin":
429+
AF_BLUETOOTH: int
426430

427431
AF_UNIX: AddressFamily
428432
AF_INET: AddressFamily
@@ -463,7 +467,7 @@ if sys.platform == "linux":
463467
if sys.version_info >= (3, 8):
464468
AF_QIPCRTR: AddressFamily
465469
AF_LINK: AddressFamily # availability: BSD, macOS
466-
if sys.platform != "win32" and sys.platform != "darwin":
470+
if sys.platform != "darwin":
467471
AF_BLUETOOTH: AddressFamily
468472

469473
class SocketKind(IntEnum):
@@ -472,8 +476,9 @@ class SocketKind(IntEnum):
472476
SOCK_RAW: int
473477
SOCK_RDM: int
474478
SOCK_SEQPACKET: int
475-
SOCK_CLOEXEC: int
476-
SOCK_NONBLOCK: int
479+
if sys.platform == "linux":
480+
SOCK_CLOEXEC: int
481+
SOCK_NONBLOCK: int
477482

478483
SOCK_STREAM: SocketKind
479484
SOCK_DGRAM: SocketKind
@@ -485,10 +490,22 @@ if sys.platform == "linux":
485490
SOCK_NONBLOCK: SocketKind
486491

487492
class MsgFlag(IntFlag):
493+
MSG_BCAST: int
494+
MSG_BTAG: int
495+
MSG_CMSG_CLOEXEC: int
496+
MSG_CONFIRM: int
488497
MSG_CTRUNC: int
489498
MSG_DONTROUTE: int
490499
MSG_DONTWAIT: int
500+
MSG_EOF: int
491501
MSG_EOR: int
502+
MSG_ERRQUEUE: int
503+
MSG_ETAG: int
504+
MSG_FASTOPEN: int
505+
MSG_MCAST: int
506+
MSG_MORE: int
507+
MSG_NOSIGNAL: int
508+
MSG_NOTIFICATION: int
492509
MSG_OOB: int
493510
MSG_PEEK: int
494511
MSG_TRUNC: int
@@ -519,10 +536,13 @@ class AddressInfo(IntFlag):
519536
AI_ADDRCONFIG: int
520537
AI_ALL: int
521538
AI_CANONNAME: int
539+
AI_DEFAULT: int
540+
AI_MASK: int
522541
AI_NUMERICHOST: int
523542
AI_NUMERICSERV: int
524543
AI_PASSIVE: int
525544
AI_V4MAPPED: int
545+
AI_V4MAPPED_CFG: int
526546

527547
AI_ADDRCONFIG: AddressInfo
528548
AI_ALL: AddressInfo

tests/stubtest_allowlists/darwin.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ distutils.msvccompiler.MSVCCompiler.set_path_env_var
1616
distutils.msvccompiler.MacroExpander
1717
mimetypes.MimeTypes.read_windows_registry
1818
selectors.DefaultSelector.fileno
19-
socket.AddressInfo.AI_DEFAULT
20-
socket.AddressInfo.AI_MASK
21-
socket.AddressInfo.AI_V4MAPPED_CFG
22-
socket.MsgFlag.MSG_EOF
2319

2420
posix.NGROUPS_MAX
2521
posix.error.characters_written

tests/stubtest_allowlists/linux.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ distutils.msvccompiler.MSVCCompiler.set_path_env_var
1717
distutils.msvccompiler.MacroExpander
1818
mimetypes.MimeTypes.read_windows_registry
1919
selectors.DefaultSelector.fileno
20-
socket.MsgFlag.MSG_CMSG_CLOEXEC
21-
socket.MsgFlag.MSG_CONFIRM
22-
socket.MsgFlag.MSG_ERRQUEUE
23-
socket.MsgFlag.MSG_FASTOPEN
24-
socket.MsgFlag.MSG_MORE
25-
socket.MsgFlag.MSG_NOSIGNAL
2620
spwd.struct_spwd.sp_nam
2721
spwd.struct_spwd.sp_pwd
2822

tests/stubtest_allowlists/win32-py310.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ asyncio.windows_events.IocpProactor.recvfrom
99
asyncio.windows_events.IocpProactor.sendto
1010
distutils.command.build_ext.__warningregistry__
1111
msvcrt.GetErrorMode
12-
socket.MsgFlag.MSG_ERRQUEUE
1312
subprocess.STARTUPINFO.copy
1413

1514
# ==========

tests/stubtest_allowlists/win32-py311.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ asyncio.windows_events.IocpProactor.sendto
1212
distutils.command.build_ext.__warningregistry__
1313
msvcrt.GetErrorMode
1414
os.EX_OK
15-
socket.MsgFlag.MSG_ERRQUEUE
1615
subprocess.STARTUPINFO.copy
1716

1817
# ==========

tests/stubtest_allowlists/win32-py37.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ urllib.parse.parse_qsl
1010

1111
os.startfile
1212

13-
# Exists at runtime, but missing from stubs
14-
socket.MsgFlag.MSG_ERRQUEUE
15-
1613
# ==========
1714
# Allowlist entries that cannot or should not be fixed
1815
# ==========

tests/stubtest_allowlists/win32-py38.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ asyncio.IocpProactor.recvfrom
77
asyncio.IocpProactor.sendto
88
asyncio.windows_events.IocpProactor.recvfrom
99
asyncio.windows_events.IocpProactor.sendto
10-
socket.MsgFlag.MSG_ERRQUEUE
1110
subprocess.STARTUPINFO.copy
1211

1312
# ==========

tests/stubtest_allowlists/win32-py39.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ asyncio.IocpProactor.recvfrom
77
asyncio.IocpProactor.sendto
88
asyncio.windows_events.IocpProactor.recvfrom
99
asyncio.windows_events.IocpProactor.sendto
10-
socket.MsgFlag.MSG_ERRQUEUE
1110
subprocess.STARTUPINFO.copy
1211

1312
# ==========

tests/stubtest_allowlists/win32.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ distutils.msvccompiler.MSVCCompiler.manifest_get_embed_info
2727
distutils.msvccompiler.MSVCCompiler.manifest_setup_ldargs
2828
distutils.msvccompiler.OldMSVCCompiler
2929
msvcrt.SetErrorMode
30-
socket.MsgFlag.MSG_BCAST
31-
socket.MsgFlag.MSG_MCAST
3230
ssl.SSLSocket.recvmsg
3331
ssl.SSLSocket.recvmsg_into
3432
ssl.SSLSocket.sendmsg

0 commit comments

Comments
 (0)