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:
Daniel Farley
2020-01-08 17:25:36 -08:00
committed by Rebecca Chen
parent 1651348a08
commit 955e9c7da4
10 changed files with 84 additions and 86 deletions

View File

@@ -1,6 +1,7 @@
# Stubs for fcntl
from io import IOBase
from typing import Any, IO, Union
from _types import FileDescriptorLike
FASYNC: int
FD_CLOEXEC: int
@@ -75,21 +76,19 @@ LOCK_SH: int
LOCK_UN: int
LOCK_WRITE: int
_AnyFile = Union[int, IO[Any], IOBase]
# TODO All these return either int or bytes depending on the value of
# cmd (not on the type of arg).
def fcntl(fd: _AnyFile,
def fcntl(fd: FileDescriptorLike,
cmd: int,
arg: Union[int, bytes] = ...) -> Any: ...
# TODO This function accepts any object supporting a buffer interface,
# as arg, is there a better way to express this than bytes?
def ioctl(fd: _AnyFile,
def ioctl(fd: FileDescriptorLike,
request: int,
arg: Union[int, bytes] = ...,
mutate_flag: bool = ...) -> Any: ...
def flock(fd: _AnyFile, operation: int) -> None: ...
def lockf(fd: _AnyFile,
def flock(fd: FileDescriptorLike, operation: int) -> None: ...
def lockf(fd: FileDescriptorLike,
cmd: int,
len: int = ...,
start: int = ...,