From 05250e62ee17e24d30c28ffaa0d6ac6c5e87594b Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 15 Jun 2019 11:57:31 -0700 Subject: [PATCH] Update select and selectors to use _HasFileno protocol --- stdlib/2and3/select.pyi | 9 +++++---- stdlib/3/selectors.pyi | 10 ++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/stdlib/2and3/select.pyi b/stdlib/2and3/select.pyi index ab9ffc63603a..3fc05450bc40 100644 --- a/stdlib/2and3/select.pyi +++ b/stdlib/2and3/select.pyi @@ -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 diff --git a/stdlib/3/selectors.pyi b/stdlib/3/selectors.pyi index 39e68ce7950a..6dd864795fc7 100644 --- a/stdlib/3/selectors.pyi +++ b/stdlib/3/selectors.pyi @@ -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