Update select and selectors to use _HasFileno protocol (#3057)

This commit is contained in:
Eric Arellano
2019-06-15 16:35:18 -07:00
committed by Jelle Zijlstra
parent 1f740a7926
commit d36a519b95
2 changed files with 9 additions and 10 deletions

View File

@@ -1,9 +1,10 @@
import sys
from typing import Any, Optional, Sequence, Tuple, Iterable, List, Union
from typing import Any, Iterable, List, Optional, Protocol, Sequence, Tuple, Union
# When we have protocols, this should change to a protocol with a fileno method
# See https://docs.python.org/3/c-api/file.html#c.PyObject_AsFileDescriptor
_FileDescriptor = Union[int, Any]
class _HasFileno(Protocol):
def fileno(self) -> int: ...
_FileDescriptor = Union[int, _HasFileno]
EPOLLERR: int
EPOLLET: int

View File

@@ -1,16 +1,14 @@
# Stubs for selector
# See https://docs.python.org/3/library/selectors.html
from typing import Any, List, NamedTuple, Mapping, Tuple, Optional, Union
from abc import ABCMeta, abstractmethod
import socket
from typing import Any, List, Mapping, NamedTuple, Optional, Protocol, Tuple, Union
class _HasFileno(Protocol):
def fileno(self) -> int: ...
# Type aliases added mainly to preserve some context
#
# See https://github.com/python/typeshed/issues/482
# for details regarding how _FileObject is typed.
_FileObject = Union[int, socket.socket]
_FileObject = Union[int, _HasFileno]
_FileDescriptor = int
_EventMask = int