mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
Unify file descriptor definitions (#3584)
The _types module can house any common type defintions used throughout the rest of typeshed to keep defintions in sync. First candidate is file descriptors where anything with `fileno()` method is accepted. There were several different implementations in various files that can be unified.
This commit is contained in:
committed by
Rebecca Chen
parent
1651348a08
commit
955e9c7da4
@@ -1,10 +1,7 @@
|
||||
import sys
|
||||
from typing import Any, Iterable, List, Optional, Protocol, Tuple, Union
|
||||
from _types import FileDescriptorLike
|
||||
|
||||
class _HasFileno(Protocol):
|
||||
def fileno(self) -> int: ...
|
||||
|
||||
_FileDescriptor = Union[int, _HasFileno]
|
||||
|
||||
EPOLLERR: int
|
||||
EPOLLET: int
|
||||
@@ -71,9 +68,9 @@ POLLWRNORM: int
|
||||
|
||||
class poll:
|
||||
def __init__(self) -> None: ...
|
||||
def register(self, fd: _FileDescriptor, eventmask: int = ...) -> None: ...
|
||||
def modify(self, fd: _FileDescriptor, eventmask: int) -> None: ...
|
||||
def unregister(self, fd: _FileDescriptor) -> None: ...
|
||||
def register(self, fd: FileDescriptorLike, eventmask: int = ...) -> None: ...
|
||||
def modify(self, fd: FileDescriptorLike, eventmask: int) -> None: ...
|
||||
def unregister(self, fd: FileDescriptorLike) -> None: ...
|
||||
def poll(self, timeout: Optional[float] = ...) -> List[Tuple[int, int]]: ...
|
||||
|
||||
def select(rlist: Iterable[Any], wlist: Iterable[Any], xlist: Iterable[Any],
|
||||
@@ -94,7 +91,7 @@ class kevent(object):
|
||||
flags: int
|
||||
ident: int
|
||||
udata: Any
|
||||
def __init__(self, ident: _FileDescriptor, filter: int = ..., flags: int = ..., fflags: int = ..., data: Any = ..., udata: Any = ...) -> None: ...
|
||||
def __init__(self, ident: FileDescriptorLike, filter: int = ..., flags: int = ..., fflags: int = ..., data: Any = ..., udata: Any = ...) -> None: ...
|
||||
|
||||
# BSD only
|
||||
class kqueue(object):
|
||||
@@ -104,7 +101,7 @@ class kqueue(object):
|
||||
def control(self, changelist: Optional[Iterable[kevent]], max_events: int, timeout: float = ...) -> List[kevent]: ...
|
||||
def fileno(self) -> int: ...
|
||||
@classmethod
|
||||
def fromfd(cls, fd: _FileDescriptor) -> kqueue: ...
|
||||
def fromfd(cls, fd: FileDescriptorLike) -> kqueue: ...
|
||||
|
||||
# Linux only
|
||||
class epoll(object):
|
||||
@@ -118,12 +115,12 @@ class epoll(object):
|
||||
def close(self) -> None: ...
|
||||
closed: bool
|
||||
def fileno(self) -> int: ...
|
||||
def register(self, fd: _FileDescriptor, eventmask: int = ...) -> None: ...
|
||||
def modify(self, fd: _FileDescriptor, eventmask: int) -> None: ...
|
||||
def unregister(self, fd: _FileDescriptor) -> None: ...
|
||||
def register(self, fd: FileDescriptorLike, eventmask: int = ...) -> None: ...
|
||||
def modify(self, fd: FileDescriptorLike, eventmask: int) -> None: ...
|
||||
def unregister(self, fd: FileDescriptorLike) -> None: ...
|
||||
def poll(self, timeout: float = ..., maxevents: int = ...) -> List[Tuple[int, int]]: ...
|
||||
@classmethod
|
||||
def fromfd(cls, fd: _FileDescriptor) -> epoll: ...
|
||||
def fromfd(cls, fd: FileDescriptorLike) -> epoll: ...
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
# Solaris only
|
||||
@@ -132,7 +129,7 @@ if sys.version_info >= (3, 3):
|
||||
def close(self) -> None: ...
|
||||
closed: bool
|
||||
def fileno(self) -> int: ...
|
||||
def register(self, fd: _FileDescriptor, eventmask: int = ...) -> None: ...
|
||||
def modify(self, fd: _FileDescriptor, eventmask: int = ...) -> None: ...
|
||||
def unregister(self, fd: _FileDescriptor) -> None: ...
|
||||
def register(self, fd: FileDescriptorLike, eventmask: int = ...) -> None: ...
|
||||
def modify(self, fd: FileDescriptorLike, eventmask: int = ...) -> None: ...
|
||||
def unregister(self, fd: FileDescriptorLike) -> None: ...
|
||||
def poll(self, timeout: Optional[float] = ...) -> List[Tuple[int, int]]: ...
|
||||
|
||||
Reference in New Issue
Block a user