mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 12:14:27 +08:00
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:
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import AnyPath
|
||||
from _typeshed import AnyPath, FileDescriptorLike
|
||||
from builtins import OSError as error
|
||||
from io import TextIOWrapper as _TextIOWrapper
|
||||
from posix import listdir as listdir, stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078
|
||||
@@ -211,7 +211,7 @@ def closerange(fd_low: int, fd_high: int) -> None: ...
|
||||
def dup(fd: int) -> int: ...
|
||||
def dup2(fd: int, fd2: int) -> None: ...
|
||||
def fstat(fd: int) -> Any: ...
|
||||
def fsync(fd: int) -> None: ...
|
||||
def fsync(fd: FileDescriptorLike) -> None: ...
|
||||
def lseek(fd: int, pos: int, how: int) -> int: ...
|
||||
def open(file: AnyPath, flags: int, mode: int = ...) -> int: ...
|
||||
def pipe() -> Tuple[int, int]: ...
|
||||
@@ -219,7 +219,7 @@ def read(fd: int, n: int) -> bytes: ...
|
||||
def write(fd: int, string: Union[bytes, buffer]) -> int: ...
|
||||
def access(path: AnyPath, mode: int) -> bool: ...
|
||||
def chdir(path: AnyPath) -> None: ...
|
||||
def fchdir(fd: int) -> None: ...
|
||||
def fchdir(fd: FileDescriptorLike) -> None: ...
|
||||
def getcwd() -> str: ...
|
||||
def getcwdu() -> unicode: ...
|
||||
def chmod(path: AnyPath, mode: int) -> None: ...
|
||||
@@ -257,7 +257,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: ...
|
||||
def ftruncate(fd: int, length: int) -> None: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import FileDescriptorLike
|
||||
from typing import IO, AnyStr, Dict, List, Mapping, NamedTuple, Optional, Sequence, Tuple, TypeVar, Union
|
||||
|
||||
error = OSError
|
||||
@@ -105,17 +106,17 @@ def dup(fd: int) -> int: ...
|
||||
def dup2(fd: int, fd2: int) -> None: ...
|
||||
def execv(path: str, args: Sequence[str], env: Mapping[str, str]) -> None: ...
|
||||
def execve(path: str, args: Sequence[str], env: Mapping[str, str]) -> None: ...
|
||||
def fchdir(fd: int) -> None: ...
|
||||
def fchdir(fd: FileDescriptorLike) -> None: ...
|
||||
def fchmod(fd: int, mode: int) -> None: ...
|
||||
def fchown(fd: int, uid: int, gid: int) -> None: ...
|
||||
def fdatasync(fd: int) -> None: ...
|
||||
def fdatasync(fd: FileDescriptorLike) -> None: ...
|
||||
def fdopen(fd: int, mode: str = ..., bufsize: int = ...) -> IO[str]: ...
|
||||
def fork() -> int: ...
|
||||
def forkpty() -> Tuple[int, int]: ...
|
||||
def fpathconf(fd: int, name: str) -> None: ...
|
||||
def fstat(fd: int) -> stat_result: ...
|
||||
def fstatvfs(fd: int) -> statvfs_result: ...
|
||||
def fsync(fd: int) -> None: ...
|
||||
def fsync(fd: FileDescriptorLike) -> None: ...
|
||||
def ftruncate(fd: int, length: int) -> None: ...
|
||||
def getcwd() -> str: ...
|
||||
def getcwdu() -> unicode: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user