-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
I'm currently trying to add types for the selectors module, and am running into some difficulty figuring out the correct way to type a "file object".
The documentation for BaseSelector states that...
fileobj is the file object to monitor. It may either be an integer file descriptor or an object with a fileno() method.
However, the problem is that there doesn't seem to an ABC that exactly describes "an object with a fileno() method". I initially tried using io.IOBase and typing.IO
, but the socket class doesn't seem to extend either base class (or share many of the methods, for that matter).
What is the correct course of action here? Should I try and petition to add a new ABC/modify the io module to try and unify all these different kinds of "file-like objects", or should I just settle for something more ad-hoc like the following?
from socket import socket
from io import IOBase
from typing import AnyStr, IO, Union
FileObj = Union[int, socket, IOBase, IO[AnyStr]]
(Oddly, io.IOBase and typing.IO also seem to be two distinct classes despite them being fairly similar -- I'm not sure if that was intentional or not)