From b3b5661f80af9b6d3106f9e8f140ff04d28e9a71 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 2 Oct 2023 13:15:49 +0300 Subject: [PATCH] Add `DefaultSelector.fileno` on platforms where it exists (#10820) --- stdlib/selectors.pyi | 5 +++++ tests/stubtest_allowlists/darwin.txt | 1 - tests/stubtest_allowlists/linux.txt | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/selectors.pyi b/stdlib/selectors.pyi index 90a923f09..598ed40f9 100644 --- a/stdlib/selectors.pyi +++ b/stdlib/selectors.pyi @@ -66,8 +66,13 @@ class KqueueSelector(BaseSelector): def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ... def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ... +# Not a real class at runtime, it is just a conditional alias to other real selectors. +# The runtime logic is more fine-grained than a `sys.platform` check; +# not really expressible in the stubs class DefaultSelector(BaseSelector): def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ... def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ... def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ... def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ... + if sys.platform != "win32": + def fileno(self) -> int: ... diff --git a/tests/stubtest_allowlists/darwin.txt b/tests/stubtest_allowlists/darwin.txt index 312e12481..d3f64a642 100644 --- a/tests/stubtest_allowlists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -30,7 +30,6 @@ select.POLLMSG # system dependent # Exists at runtime, but missing from stubs mimetypes.MimeTypes.read_windows_registry -selectors.DefaultSelector.fileno _ctypes.dlclose _ctypes.dlopen diff --git a/tests/stubtest_allowlists/linux.txt b/tests/stubtest_allowlists/linux.txt index 2db6ec1f3..930d4ed0f 100644 --- a/tests/stubtest_allowlists/linux.txt +++ b/tests/stubtest_allowlists/linux.txt @@ -15,7 +15,6 @@ socket.[A-Z0-9_]+ # Exists at runtime, but missing from stubs mimetypes.MimeTypes.read_windows_registry -selectors.DefaultSelector.fileno spwd.struct_spwd.sp_nam spwd.struct_spwd.sp_pwd