From c6161f7108fd80a0caade8b654014d628f359b05 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Thu, 28 Sep 2023 13:36:25 +0200 Subject: [PATCH] Limit `os.sendfile` arguments based on platform (#10790) --- stdlib/os/__init__.pyi | 26 ++++++++++++----------- tests/stubtest_allowlists/linux-py310.txt | 1 - tests/stubtest_allowlists/linux-py311.txt | 1 - tests/stubtest_allowlists/linux-py312.txt | 1 - tests/stubtest_allowlists/linux-py39.txt | 1 - 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 3d5dc3d15..5938901b6 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -657,18 +657,20 @@ if sys.platform != "win32": RWF_SYNC: int RWF_HIPRI: int RWF_NOWAIT: int - @overload - def sendfile(out_fd: int, in_fd: int, offset: int | None, count: int) -> int: ... - @overload - def sendfile( - out_fd: int, - in_fd: int, - offset: int, - count: int, - headers: Sequence[ReadableBuffer] = ..., - trailers: Sequence[ReadableBuffer] = ..., - flags: int = 0, - ) -> int: ... # FreeBSD and Mac OS X only + + if sys.platform == "linux": + def sendfile(out_fd: FileDescriptor, in_fd: FileDescriptor, offset: int | None, count: int) -> int: ... + else: + def sendfile( + out_fd: FileDescriptor, + in_fd: FileDescriptor, + offset: int, + count: int, + headers: Sequence[ReadableBuffer] = ..., + trailers: Sequence[ReadableBuffer] = ..., + flags: int = 0, + ) -> int: ... # FreeBSD and Mac OS X only + def readv(__fd: int, __buffers: SupportsLenAndGetItem[WriteableBuffer]) -> int: ... def writev(__fd: int, __buffers: SupportsLenAndGetItem[ReadableBuffer]) -> int: ... diff --git a/tests/stubtest_allowlists/linux-py310.txt b/tests/stubtest_allowlists/linux-py310.txt index 77992cc8b..1e973da0b 100644 --- a/tests/stubtest_allowlists/linux-py310.txt +++ b/tests/stubtest_allowlists/linux-py310.txt @@ -1,5 +1,4 @@ _?curses.color_pair -(os|posix).sendfile signal.sigtimedwait signal.sigwaitinfo diff --git a/tests/stubtest_allowlists/linux-py311.txt b/tests/stubtest_allowlists/linux-py311.txt index 7ef0ad0a6..97aec2409 100644 --- a/tests/stubtest_allowlists/linux-py311.txt +++ b/tests/stubtest_allowlists/linux-py311.txt @@ -1,5 +1,4 @@ _?curses.color_pair -(os|posix).sendfile signal.sigtimedwait signal.sigwaitinfo xxlimited.Xxo.x_exports diff --git a/tests/stubtest_allowlists/linux-py312.txt b/tests/stubtest_allowlists/linux-py312.txt index 05f78a9db..9423e9413 100644 --- a/tests/stubtest_allowlists/linux-py312.txt +++ b/tests/stubtest_allowlists/linux-py312.txt @@ -1,6 +1,5 @@ _?curses.color_pair _posixsubprocess.fork_exec -(os|posix).sendfile (os|posix).setns resource.prlimit signal.sigtimedwait diff --git a/tests/stubtest_allowlists/linux-py39.txt b/tests/stubtest_allowlists/linux-py39.txt index 0002c91df..b81a540ec 100644 --- a/tests/stubtest_allowlists/linux-py39.txt +++ b/tests/stubtest_allowlists/linux-py39.txt @@ -1,4 +1,3 @@ -(os|posix).sendfile select.epoll.register # ==========