Skip to content

Commit ae241b1

Browse files
authored
Remove selector._EventMask type alias (#15771)
1 parent d80ed91 commit ae241b1

3 files changed

Lines changed: 17 additions & 21 deletions

File tree

stdlib/selectors.pyi

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,26 @@ import sys
22
from _typeshed import FileDescriptor, FileDescriptorLike, Unused
33
from abc import ABCMeta, abstractmethod
44
from collections.abc import Mapping
5-
from typing import Any, Final, NamedTuple, TypeAlias
5+
from typing import Any, Final, NamedTuple
66
from typing_extensions import Self
77

8-
_EventMask: TypeAlias = int
9-
108
EVENT_READ: Final = 1
119
EVENT_WRITE: Final = 2
1210

1311
class SelectorKey(NamedTuple):
1412
fileobj: FileDescriptorLike
1513
fd: FileDescriptor
16-
events: _EventMask
14+
events: int
1715
data: Any
1816

1917
class BaseSelector(metaclass=ABCMeta):
2018
@abstractmethod
21-
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
19+
def register(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ...
2220
@abstractmethod
2321
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
24-
def modify(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
22+
def modify(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ...
2523
@abstractmethod
26-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
24+
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ...
2725
def close(self) -> None: ...
2826
def get_key(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
2927
@abstractmethod
@@ -32,16 +30,16 @@ class BaseSelector(metaclass=ABCMeta):
3230
def __exit__(self, *args: Unused) -> None: ...
3331

3432
class _BaseSelectorImpl(BaseSelector, metaclass=ABCMeta):
35-
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
33+
def register(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ...
3634
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
37-
def modify(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
35+
def modify(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ...
3836
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
3937

4038
class SelectSelector(_BaseSelectorImpl):
41-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
39+
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ...
4240

4341
class _PollLikeSelector(_BaseSelectorImpl):
44-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
42+
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ...
4543

4644
if sys.platform != "win32":
4745
class PollSelector(_PollLikeSelector): ...
@@ -58,12 +56,12 @@ if sys.platform != "linux" and sys.platform != "darwin" and sys.platform != "win
5856
if sys.platform != "win32" and sys.platform != "linux":
5957
class KqueueSelector(_BaseSelectorImpl):
6058
def fileno(self) -> int: ...
61-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
59+
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ...
6260

6361
# Not a real class at runtime, it is just a conditional alias to other real selectors.
6462
# The runtime logic is more fine-grained than a `sys.platform` check;
6563
# not really expressible in the stubs
6664
class DefaultSelector(_BaseSelectorImpl):
67-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
65+
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ...
6866
if sys.platform != "win32":
6967
def fileno(self) -> int: ...

stubs/gevent/gevent/selectors.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
from _typeshed import FileDescriptorLike
22
from collections.abc import Mapping
33
from selectors import BaseSelector, SelectorKey
4-
from typing import Any, TypeAlias
4+
from typing import Any
55

66
from gevent._util import Lazy
77
from gevent.hub import Hub
88

99
__all__ = ["DefaultSelector", "GeventSelector"]
1010

11-
_EventMask: TypeAlias = int
12-
1311
# technically this derives from _BaseSelectorImpl, which does not have type annotations
1412
# but in terms of type checking the only difference is, that we need to add get_map since
1513
# GeventSelector does not override it
1614
class GeventSelector(BaseSelector):
1715
def __init__(self, hub: Hub | None = None) -> None: ...
1816
@Lazy
1917
def hub(self) -> Hub: ...
20-
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
18+
def register(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ...
2119
def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
22-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
20+
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ...
2321
def close(self) -> None: ...
2422
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
2523

stubs/simple-websocket/simple_websocket/ws.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import threading
33
from _typeshed import FileDescriptorLike
44
from _typeshed.wsgi import WSGIEnvironment
55
from collections.abc import Callable
6-
from selectors import SelectorKey, _EventMask
6+
from selectors import SelectorKey
77
from ssl import SSLContext
88
from typing import Any, Protocol, type_check_only
99

@@ -27,9 +27,9 @@ class _EventClassProtocol(Protocol):
2727
@type_check_only
2828
class _SelectorClassProtocol(Protocol):
2929
# the signature of `register` here is the same as `selectors._BaseSelectorImpl` from the stdlib
30-
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = None) -> SelectorKey: ...
30+
def register(self, fileobj: FileDescriptorLike, events: int, data: Any = None) -> SelectorKey: ...
3131
# the signature of `select` here is the same as `selectors.DefaultSelector` from the stdlib
32-
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
32+
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, int]]: ...
3333
def close(self) -> None: ...
3434

3535
class Base:

0 commit comments

Comments
 (0)