From 7155bdae63eed76a124e93d347fc5f13d4e501c4 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 7 Dec 2021 17:10:41 +0200 Subject: [PATCH] Re-export more os functions in posix, tweak availability on linux (#6529) --- stdlib/os/__init__.pyi | 18 +++++++----------- stdlib/posix.pyi | 7 +++++++ tests/stubtest_allowlists/darwin.txt | 6 ------ tests/stubtest_allowlists/linux-py310.txt | 1 - tests/stubtest_allowlists/linux.txt | 7 ------- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 94d56a167..7289ac425 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -575,8 +575,6 @@ if sys.platform != "win32": # Unix only def fchmod(fd: int, mode: int) -> None: ... def fchown(fd: int, uid: int, gid: int) -> None: ... - if sys.platform != "darwin": - def fdatasync(fd: FileDescriptorLike) -> None: ... # Unix only, not Mac def fpathconf(__fd: int, __name: str | int) -> int: ... def fstatvfs(__fd: int) -> statvfs_result: ... def get_blocking(__fd: int) -> bool: ... @@ -584,7 +582,8 @@ if sys.platform != "win32": def lockf(__fd: int, __command: int, __length: int) -> None: ... def openpty() -> tuple[int, int]: ... # some flavors of Unix if sys.platform != "darwin": - def pipe2(flags: int) -> tuple[int, int]: ... # some flavors of Unix + def fdatasync(fd: FileDescriptorLike) -> None: ... + def pipe2(__flags: int) -> tuple[int, int]: ... # some flavors of Unix def posix_fallocate(fd: int, offset: int, length: int) -> None: ... def posix_fadvise(fd: int, offset: int, length: int, advice: int) -> None: ... def pread(__fd: int, __length: int, __offset: int) -> bytes: ... @@ -632,17 +631,14 @@ def getcwd() -> str: ... def getcwdb() -> bytes: ... def chmod(path: _FdOrAnyPath, mode: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> None: ... -if sys.platform != "win32": +if sys.platform != "win32" and sys.platform != "linux": def chflags(path: StrOrBytesPath, flags: int, follow_symlinks: bool = ...) -> None: ... # some flavors of Unix - def chown( - path: _FdOrAnyPath, uid: int, gid: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ... - ) -> None: ... # Unix only - -if sys.platform != "win32": - # Unix only - def chroot(path: StrOrBytesPath) -> None: ... def lchflags(path: StrOrBytesPath, flags: int) -> None: ... def lchmod(path: StrOrBytesPath, mode: int) -> None: ... + +if sys.platform != "win32": + def chroot(path: StrOrBytesPath) -> None: ... + def chown(path: _FdOrAnyPath, uid: int, gid: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> None: ... def lchown(path: StrOrBytesPath, uid: int, gid: int) -> None: ... def link( diff --git a/stdlib/posix.pyi b/stdlib/posix.pyi index 21af3c2d2..cdca4235d 100644 --- a/stdlib/posix.pyi +++ b/stdlib/posix.pyi @@ -103,6 +103,7 @@ if sys.platform != "win32": ctermid as ctermid, device_encoding as device_encoding, dup as dup, + dup2 as dup2, error as error, execv as execv, execve as execve, @@ -212,6 +213,8 @@ if sys.platform != "win32": urandom as urandom, utime as utime, wait as wait, + wait3 as wait3, + wait4 as wait4, waitpid as waitpid, write as write, writev as writev, @@ -231,6 +234,9 @@ if sys.platform != "win32": removexattr as removexattr, setxattr as setxattr, ) + else: + from os import chflags as chflags, lchflags as lchflags, lchmod as lchmod + if sys.platform != "darwin": from os import ( POSIX_FADV_DONTNEED as POSIX_FADV_DONTNEED, @@ -242,6 +248,7 @@ if sys.platform != "win32": fdatasync as fdatasync, getresgid as getresgid, getresuid as getresuid, + pipe2 as pipe2, posix_fadvise as posix_fadvise, posix_fallocate as posix_fallocate, sched_getaffinity as sched_getaffinity, diff --git a/tests/stubtest_allowlists/darwin.txt b/tests/stubtest_allowlists/darwin.txt index a22f178e1..6d594959a 100644 --- a/tests/stubtest_allowlists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -57,12 +57,6 @@ grp.struct_group.n_unnamed_fields mimetypes.MimeTypes.read_windows_registry os.ST_NOSUID os.ST_RDONLY -posix.chflags -posix.dup2 -posix.lchflags -posix.lchmod -posix.wait3 -posix.wait4 resource.struct_rusage.n_fields resource.struct_rusage.n_sequence_fields resource.struct_rusage.n_unnamed_fields diff --git a/tests/stubtest_allowlists/linux-py310.txt b/tests/stubtest_allowlists/linux-py310.txt index b02c93538..768560017 100644 --- a/tests/stubtest_allowlists/linux-py310.txt +++ b/tests/stubtest_allowlists/linux-py310.txt @@ -1,6 +1,5 @@ _curses.color_pair curses.color_pair -os.pipe2 (os|posix).posix_fadvise (os|posix).posix_fallocate (os|posix).sched_getaffinity diff --git a/tests/stubtest_allowlists/linux.txt b/tests/stubtest_allowlists/linux.txt index 1bcea1d49..bff6db8eb 100644 --- a/tests/stubtest_allowlists/linux.txt +++ b/tests/stubtest_allowlists/linux.txt @@ -12,9 +12,6 @@ os.EX_NOTFOUND os.SF_MNOWAIT os.SF_NODISKIO os.SF_SYNC -os.chflags -os.lchflags -os.lchmod os.plock posix.EX_NOTFOUND select.EPOLL_RDHUP @@ -65,10 +62,6 @@ mimetypes.MimeTypes.read_windows_registry (os|posix).waitid_result.n_fields (os|posix).waitid_result.n_sequence_fields (os|posix).waitid_result.n_unnamed_fields -posix.dup2 -posix.pipe2 -posix.wait3 -posix.wait4 resource.struct_rusage.n_fields resource.struct_rusage.n_sequence_fields resource.struct_rusage.n_unnamed_fields