From b7f8d847be2c19eea409444853c601c6113991e2 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sun, 19 Jun 2022 00:57:55 -0700 Subject: [PATCH] socket: consistency between constants and enums (#8099) This matches what happens at runtime, from Enum._convert_ Helps with #8098. Closes #5696. --- stdlib/socket.pyi | 46 ++++++++++++++++------- tests/stubtest_allowlists/darwin.txt | 4 -- tests/stubtest_allowlists/linux.txt | 6 --- tests/stubtest_allowlists/win32-py310.txt | 1 - tests/stubtest_allowlists/win32-py311.txt | 1 - tests/stubtest_allowlists/win32-py37.txt | 3 -- tests/stubtest_allowlists/win32-py38.txt | 1 - tests/stubtest_allowlists/win32-py39.txt | 1 - tests/stubtest_allowlists/win32.txt | 2 - 9 files changed, 33 insertions(+), 32 deletions(-) diff --git a/stdlib/socket.pyi b/stdlib/socket.pyi index d84fd66b8..849b56f52 100644 --- a/stdlib/socket.pyi +++ b/stdlib/socket.pyi @@ -390,39 +390,43 @@ class AddressFamily(IntEnum): AF_INET: int AF_INET6: int AF_AAL5: int - AF_ALG: int AF_APPLETALK: int AF_ASH: int AF_ATMPVC: int AF_ATMSVC: int AF_AX25: int - AF_BLUETOOTH: int AF_BRIDGE: int - AF_CAN: int AF_DECnet: int AF_ECONET: int AF_IPX: int AF_IRDA: int AF_KEY: int - AF_LINK: int AF_LLC: int AF_NETBEUI: int - AF_NETLINK: int AF_NETROM: int - AF_PACKET: int AF_PPPOX: int - AF_QIPCRTR: int - AF_RDS: int AF_ROSE: int AF_ROUTE: int AF_SECURITY: int AF_SNA: int AF_SYSTEM: int - AF_TIPC: int AF_UNSPEC: int - AF_VSOCK: int AF_WANPIPE: int AF_X25: int + if sys.platform == "linux": + AF_CAN: int + AF_PACKET: int + AF_RDS: int + AF_TIPC: int + AF_ALG: int + AF_NETLINK: int + if sys.version_info >= (3, 7): + AF_VSOCK: int + if sys.version_info >= (3, 8): + AF_QIPCRTR: int + AF_LINK: AddressFamily # availability: BSD, macOS + if sys.platform != "darwin": + AF_BLUETOOTH: int AF_UNIX: AddressFamily AF_INET: AddressFamily @@ -463,7 +467,7 @@ if sys.platform == "linux": if sys.version_info >= (3, 8): AF_QIPCRTR: AddressFamily AF_LINK: AddressFamily # availability: BSD, macOS -if sys.platform != "win32" and sys.platform != "darwin": +if sys.platform != "darwin": AF_BLUETOOTH: AddressFamily class SocketKind(IntEnum): @@ -472,8 +476,9 @@ class SocketKind(IntEnum): SOCK_RAW: int SOCK_RDM: int SOCK_SEQPACKET: int - SOCK_CLOEXEC: int - SOCK_NONBLOCK: int + if sys.platform == "linux": + SOCK_CLOEXEC: int + SOCK_NONBLOCK: int SOCK_STREAM: SocketKind SOCK_DGRAM: SocketKind @@ -485,10 +490,22 @@ if sys.platform == "linux": SOCK_NONBLOCK: SocketKind class MsgFlag(IntFlag): + MSG_BCAST: int + MSG_BTAG: int + MSG_CMSG_CLOEXEC: int + MSG_CONFIRM: int MSG_CTRUNC: int MSG_DONTROUTE: int MSG_DONTWAIT: int + MSG_EOF: int MSG_EOR: int + MSG_ERRQUEUE: int + MSG_ETAG: int + MSG_FASTOPEN: int + MSG_MCAST: int + MSG_MORE: int + MSG_NOSIGNAL: int + MSG_NOTIFICATION: int MSG_OOB: int MSG_PEEK: int MSG_TRUNC: int @@ -519,10 +536,13 @@ class AddressInfo(IntFlag): AI_ADDRCONFIG: int AI_ALL: int AI_CANONNAME: int + AI_DEFAULT: int + AI_MASK: int AI_NUMERICHOST: int AI_NUMERICSERV: int AI_PASSIVE: int AI_V4MAPPED: int + AI_V4MAPPED_CFG: int AI_ADDRCONFIG: AddressInfo AI_ALL: AddressInfo diff --git a/tests/stubtest_allowlists/darwin.txt b/tests/stubtest_allowlists/darwin.txt index f054ba89c..70f480225 100644 --- a/tests/stubtest_allowlists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -16,10 +16,6 @@ distutils.msvccompiler.MSVCCompiler.set_path_env_var distutils.msvccompiler.MacroExpander mimetypes.MimeTypes.read_windows_registry selectors.DefaultSelector.fileno -socket.AddressInfo.AI_DEFAULT -socket.AddressInfo.AI_MASK -socket.AddressInfo.AI_V4MAPPED_CFG -socket.MsgFlag.MSG_EOF posix.NGROUPS_MAX posix.error.characters_written diff --git a/tests/stubtest_allowlists/linux.txt b/tests/stubtest_allowlists/linux.txt index f352c3631..849d8862c 100644 --- a/tests/stubtest_allowlists/linux.txt +++ b/tests/stubtest_allowlists/linux.txt @@ -17,12 +17,6 @@ distutils.msvccompiler.MSVCCompiler.set_path_env_var distutils.msvccompiler.MacroExpander mimetypes.MimeTypes.read_windows_registry selectors.DefaultSelector.fileno -socket.MsgFlag.MSG_CMSG_CLOEXEC -socket.MsgFlag.MSG_CONFIRM -socket.MsgFlag.MSG_ERRQUEUE -socket.MsgFlag.MSG_FASTOPEN -socket.MsgFlag.MSG_MORE -socket.MsgFlag.MSG_NOSIGNAL spwd.struct_spwd.sp_nam spwd.struct_spwd.sp_pwd diff --git a/tests/stubtest_allowlists/win32-py310.txt b/tests/stubtest_allowlists/win32-py310.txt index e28796267..f09fbeef1 100644 --- a/tests/stubtest_allowlists/win32-py310.txt +++ b/tests/stubtest_allowlists/win32-py310.txt @@ -9,7 +9,6 @@ asyncio.windows_events.IocpProactor.recvfrom asyncio.windows_events.IocpProactor.sendto distutils.command.build_ext.__warningregistry__ msvcrt.GetErrorMode -socket.MsgFlag.MSG_ERRQUEUE subprocess.STARTUPINFO.copy # ========== diff --git a/tests/stubtest_allowlists/win32-py311.txt b/tests/stubtest_allowlists/win32-py311.txt index d13534422..714d8e364 100644 --- a/tests/stubtest_allowlists/win32-py311.txt +++ b/tests/stubtest_allowlists/win32-py311.txt @@ -12,7 +12,6 @@ asyncio.windows_events.IocpProactor.sendto distutils.command.build_ext.__warningregistry__ msvcrt.GetErrorMode os.EX_OK -socket.MsgFlag.MSG_ERRQUEUE subprocess.STARTUPINFO.copy # ========== diff --git a/tests/stubtest_allowlists/win32-py37.txt b/tests/stubtest_allowlists/win32-py37.txt index a57fb445a..880275add 100644 --- a/tests/stubtest_allowlists/win32-py37.txt +++ b/tests/stubtest_allowlists/win32-py37.txt @@ -10,9 +10,6 @@ urllib.parse.parse_qsl os.startfile -# Exists at runtime, but missing from stubs -socket.MsgFlag.MSG_ERRQUEUE - # ========== # Allowlist entries that cannot or should not be fixed # ========== diff --git a/tests/stubtest_allowlists/win32-py38.txt b/tests/stubtest_allowlists/win32-py38.txt index ecb7cd493..c5d139f1c 100644 --- a/tests/stubtest_allowlists/win32-py38.txt +++ b/tests/stubtest_allowlists/win32-py38.txt @@ -7,7 +7,6 @@ asyncio.IocpProactor.recvfrom asyncio.IocpProactor.sendto asyncio.windows_events.IocpProactor.recvfrom asyncio.windows_events.IocpProactor.sendto -socket.MsgFlag.MSG_ERRQUEUE subprocess.STARTUPINFO.copy # ========== diff --git a/tests/stubtest_allowlists/win32-py39.txt b/tests/stubtest_allowlists/win32-py39.txt index ccabd9845..99f799023 100644 --- a/tests/stubtest_allowlists/win32-py39.txt +++ b/tests/stubtest_allowlists/win32-py39.txt @@ -7,7 +7,6 @@ asyncio.IocpProactor.recvfrom asyncio.IocpProactor.sendto asyncio.windows_events.IocpProactor.recvfrom asyncio.windows_events.IocpProactor.sendto -socket.MsgFlag.MSG_ERRQUEUE subprocess.STARTUPINFO.copy # ========== diff --git a/tests/stubtest_allowlists/win32.txt b/tests/stubtest_allowlists/win32.txt index 1a75c8d30..4a13971ad 100644 --- a/tests/stubtest_allowlists/win32.txt +++ b/tests/stubtest_allowlists/win32.txt @@ -27,8 +27,6 @@ distutils.msvccompiler.MSVCCompiler.manifest_get_embed_info distutils.msvccompiler.MSVCCompiler.manifest_setup_ldargs distutils.msvccompiler.OldMSVCCompiler msvcrt.SetErrorMode -socket.MsgFlag.MSG_BCAST -socket.MsgFlag.MSG_MCAST ssl.SSLSocket.recvmsg ssl.SSLSocket.recvmsg_into ssl.SSLSocket.sendmsg