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,5 +1,6 @@
from typing import Any, Union, IO
import io
from _types import FileDescriptorLike
FASYNC: int
FD_CLOEXEC: int
@@ -72,16 +73,14 @@ LOCK_SH: int
LOCK_UN: int
LOCK_WRITE: int
_ANYFILE = Union[int, IO]
# TODO All these return either int or bytes depending on the value of
# cmd (not on the type of arg).
def fcntl(fd: _ANYFILE, op: int, arg: Union[int, bytes] = ...) -> Any: ...
def fcntl(fd: FileDescriptorLike, op: int, arg: Union[int, bytes] = ...) -> Any: ...
# TODO: arg: int or read-only buffer interface or read-write buffer interface
def ioctl(fd: _ANYFILE, op: int, arg: Union[int, bytes] = ...,
def ioctl(fd: FileDescriptorLike, op: int, arg: Union[int, bytes] = ...,
mutate_flag: bool = ...) -> Any: ...
def flock(fd: _ANYFILE, op: int) -> None: ...
def lockf(fd: _ANYFILE, op: int, length: int = ..., start: int = ...,
def flock(fd: FileDescriptorLike, op: int) -> None: ...
def lockf(fd: FileDescriptorLike, op: int, length: int = ..., start: int = ...,
whence: int = ...) -> Any: ...