Make os.fchdir, os.fsync, and os.fdatasync accept FileDescriptorLike (#4544)

For the fd passed to these functions, CPython accepts not just an int,
but also anything with a fileno() method.

Fixes #4539
This commit is contained in:
Cebtenzzre
2020-09-15 19:30:34 -04:00
committed by GitHub
parent d402f55334
commit 1334840323
3 changed files with 20 additions and 11 deletions

View File

@@ -1,5 +1,13 @@
import sys
from _typeshed import AnyPath, OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode
from _typeshed import (
AnyPath,
FileDescriptorLike,
OpenBinaryMode,
OpenBinaryModeReading,
OpenBinaryModeUpdating,
OpenBinaryModeWriting,
OpenTextMode,
)
from builtins import OSError as error
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper
from posix import listdir as listdir, times_result
@@ -489,7 +497,7 @@ else:
def dup2(fd: int, fd2: int, inheritable: bool = ...) -> None: ...
def fstat(fd: int) -> stat_result: ...
def fsync(fd: int) -> None: ...
def fsync(fd: FileDescriptorLike) -> None: ...
def lseek(__fd: int, __position: int, __how: int) -> int: ...
def open(path: AnyPath, flags: int, mode: int = ..., *, dir_fd: Optional[int] = ...) -> int: ...
def pipe() -> Tuple[int, int]: ...
@@ -500,7 +508,7 @@ if sys.platform != "win32":
def fchmod(fd: int, mode: int) -> None: ...
def fchown(fd: int, uid: int, gid: int) -> None: ...
if sys.platform != "darwin":
def fdatasync(fd: int) -> None: ... # Unix only, not Mac
def fdatasync(fd: FileDescriptorLike) -> None: ... # Unix only, not Mac
def fpathconf(__fd: int, __name: Union[str, int]) -> int: ...
def fstatvfs(__fd: int) -> statvfs_result: ...
def ftruncate(__fd: int, __length: int) -> None: ...
@@ -551,7 +559,7 @@ def access(
def chdir(path: _FdOrAnyPath) -> None: ...
if sys.platform != "win32":
def fchdir(fd: int) -> None: ...
def fchdir(fd: FileDescriptorLike) -> None: ...
def getcwd() -> str: ...
def getcwdb() -> bytes: ...