diff --git a/stdlib/selectors.pyi b/stdlib/selectors.pyi index 68822c50ece8..4a3478a67552 100644 --- a/stdlib/selectors.pyi +++ b/stdlib/selectors.pyi @@ -2,28 +2,26 @@ import sys from _typeshed import FileDescriptor, FileDescriptorLike, Unused from abc import ABCMeta, abstractmethod from collections.abc import Mapping -from typing import Any, Final, NamedTuple, TypeAlias +from typing import Any, Final, NamedTuple from typing_extensions import Self -_EventMask: TypeAlias = int - EVENT_READ: Final = 1 EVENT_WRITE: Final = 2 class SelectorKey(NamedTuple): fileobj: FileDescriptorLike fd: FileDescriptor - events: _EventMask + events: int data: Any class BaseSelector(metaclass=ABCMeta): @abstractmethod - def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ... + def register(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ... @abstractmethod def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ... - def modify(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ... + def modify(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ... @abstractmethod - def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ... + def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ... def close(self) -> None: ... def get_key(self, fileobj: FileDescriptorLike) -> SelectorKey: ... @abstractmethod @@ -32,16 +30,16 @@ class BaseSelector(metaclass=ABCMeta): def __exit__(self, *args: Unused) -> None: ... class _BaseSelectorImpl(BaseSelector, metaclass=ABCMeta): - def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ... + def register(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ... def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ... - def modify(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ... + def modify(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ... def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ... class SelectSelector(_BaseSelectorImpl): - def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ... + def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ... class _PollLikeSelector(_BaseSelectorImpl): - def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ... + def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ... if sys.platform != "win32": class PollSelector(_PollLikeSelector): ... @@ -58,12 +56,12 @@ if sys.platform != "linux" and sys.platform != "darwin" and sys.platform != "win if sys.platform != "win32" and sys.platform != "linux": class KqueueSelector(_BaseSelectorImpl): def fileno(self) -> int: ... - def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ... + def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ... # 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(_BaseSelectorImpl): - def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ... + def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ... if sys.platform != "win32": def fileno(self) -> int: ... diff --git a/stubs/gevent/gevent/selectors.pyi b/stubs/gevent/gevent/selectors.pyi index f25d16cd1f91..12614ef1e6ff 100644 --- a/stubs/gevent/gevent/selectors.pyi +++ b/stubs/gevent/gevent/selectors.pyi @@ -1,15 +1,13 @@ from _typeshed import FileDescriptorLike from collections.abc import Mapping from selectors import BaseSelector, SelectorKey -from typing import Any, TypeAlias +from typing import Any from gevent._util import Lazy from gevent.hub import Hub __all__ = ["DefaultSelector", "GeventSelector"] -_EventMask: TypeAlias = int - # technically this derives from _BaseSelectorImpl, which does not have type annotations # but in terms of type checking the only difference is, that we need to add get_map since # GeventSelector does not override it @@ -17,9 +15,9 @@ class GeventSelector(BaseSelector): def __init__(self, hub: Hub | None = None) -> None: ... @Lazy def hub(self) -> Hub: ... - def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ... + def register(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ... def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ... - def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ... + def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ... def close(self) -> None: ... def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ... diff --git a/stubs/simple-websocket/simple_websocket/ws.pyi b/stubs/simple-websocket/simple_websocket/ws.pyi index d469cd38d672..0366967d6d5a 100644 --- a/stubs/simple-websocket/simple_websocket/ws.pyi +++ b/stubs/simple-websocket/simple_websocket/ws.pyi @@ -3,7 +3,7 @@ import threading from _typeshed import FileDescriptorLike from _typeshed.wsgi import WSGIEnvironment from collections.abc import Callable -from selectors import SelectorKey, _EventMask +from selectors import SelectorKey from ssl import SSLContext from typing import Any, Protocol, type_check_only @@ -27,9 +27,9 @@ class _EventClassProtocol(Protocol): @type_check_only class _SelectorClassProtocol(Protocol): # the signature of `register` here is the same as `selectors._BaseSelectorImpl` from the stdlib - def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ... + def register(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ... # the signature of `select` here is the same as `selectors.DefaultSelector` from the stdlib - def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ... + def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ... def close(self) -> None: ... class Base: