Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add several missing stdlib functions #7397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 6, 2022
6 changes: 3 additions & 3 deletions stdlib/_msi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ if sys.platform == "win32":
__new__: None # type: ignore[assignment]
__init__: None # type: ignore[assignment]
def UuidCreate() -> str: ...
def FCICreate(cabname: str, files: list[str]) -> None: ...
def OpenDatabase(name: str, flags: int) -> _Database: ...
def CreateRecord(count: int) -> _Record: ...
def FCICreate(__cabname: str, __files: list[str]) -> None: ...
def OpenDatabase(__path: str, __persist: int) -> _Database: ...
def CreateRecord(__count: int) -> _Record: ...
4 changes: 4 additions & 0 deletions stdlib/email/iterators.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import SupportsWrite
from email.message import Message
from typing import Iterator

Expand All @@ -6,3 +7,6 @@ __all__ = ["body_line_iterator", "typed_subpart_iterator", "walk"]
def body_line_iterator(msg: Message, decode: bool = ...) -> Iterator[str]: ...
def typed_subpart_iterator(msg: Message, maintype: str = ..., subtype: str | None = ...) -> Iterator[str]: ...
def walk(self: Message) -> Iterator[Message]: ...

# We include the seemingly private function because it is documented in the stdlib documentation.
def _structure(msg: Message, fp: SupportsWrite[str] | None = ..., level: int = ..., include_default: bool = ...) -> None: ...
1 change: 1 addition & 0 deletions stdlib/errno.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ EMLINK: int
EPIPE: int
EDOM: int
ERANGE: int
EDEADLK: int
EDEADLCK: int
ENAMETOOLONG: int
ENOLCK: int
Expand Down
8 changes: 7 additions & 1 deletion stdlib/msilib/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ from typing import Any, Container, Iterable, Sequence
from typing_extensions import Literal

if sys.platform == "win32":
from _msi import _Database
from _msi import (
CreateRecord as CreateRecord,
FCICreate as FCICreate,
OpenDatabase as OpenDatabase,
UuidCreate as UuidCreate,
_Database,
)

AMD64: bool
if sys.version_info < (3, 7):
Expand Down
10 changes: 10 additions & 0 deletions stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,10 @@ def get_terminal_size(fd: int = ...) -> terminal_size: ...
def get_inheritable(__fd: int) -> bool: ...
def set_inheritable(__fd: int, __inheritable: bool) -> None: ...

if sys.platform == "win32":
def get_handle_inheritable(__handle: int) -> bool: ...
def set_handle_inheritable(__handle: int, __inheritable: bool) -> None: ...

if sys.platform != "win32":
# Unix only
def tcgetpgrp(__fd: int) -> int: ...
Expand Down Expand Up @@ -1019,6 +1023,12 @@ if sys.version_info >= (3, 8):
MFD_HUGE_2GB: int
MFD_HUGE_16GB: int
def memfd_create(name: str, flags: int = ...) -> int: ...
def copy_file_range(
src: int, dst: int, count: int, offset_src: int | None = ..., offset_dst: int | None = ...
) -> int: ...

if sys.version_info >= (3, 9):
def waitstatus_to_exitcode(status: int) -> int: ...

if sys.platform == "linux":
def pidfd_open(pid: int, flags: int = ...) -> int: ...
4 changes: 3 additions & 1 deletion stdlib/posix.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ if sys.platform != "win32":
from os import CLD_KILLED as CLD_KILLED, CLD_STOPPED as CLD_STOPPED, waitstatus_to_exitcode as waitstatus_to_exitcode

if sys.platform == "linux":
from os import P_PIDFD as P_PIDFD
from os import P_PIDFD as P_PIDFD, pidfd_open as pidfd_open

if sys.version_info >= (3, 8):
from os import (
POSIX_SPAWN_CLOSE as POSIX_SPAWN_CLOSE,
Expand Down Expand Up @@ -302,6 +303,7 @@ if sys.platform != "win32":
MFD_HUGE_MASK as MFD_HUGE_MASK,
MFD_HUGE_SHIFT as MFD_HUGE_SHIFT,
MFD_HUGETLB as MFD_HUGETLB,
copy_file_range as copy_file_range,
memfd_create as memfd_create,
)
if sys.version_info >= (3, 7):
Expand Down
4 changes: 4 additions & 0 deletions stdlib/signal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,7 @@ if sys.version_info >= (3, 7):

else:
def set_wakeup_fd(fd: int) -> int: ...

if sys.version_info >= (3, 9):
if sys.platform == "linux":
def pidfd_send_signal(__pidfd: int, __sig: int, __siginfo: None = ..., __flags: int = ...) -> None: ...
4 changes: 4 additions & 0 deletions stdlib/sys.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ class _asyncgen_hooks(structseq[_AsyncgenHook], tuple[_AsyncgenHook, _AsyncgenHo
def get_asyncgen_hooks() -> _asyncgen_hooks: ...
def set_asyncgen_hooks(firstiter: _AsyncgenHook = ..., finalizer: _AsyncgenHook = ...) -> None: ...

if sys.version_info >= (3, 6):
if sys.platform == "win32":
def _enablelegacywindowsfsencoding() -> None: ...

if sys.version_info >= (3, 7):
def get_coroutine_origin_tracking_depth() -> int: ...
def set_coroutine_origin_tracking_depth(depth: int) -> None: ...
3 changes: 3 additions & 0 deletions stdlib/time.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ if sys.version_info >= (3, 7):
def clock_gettime_ns(clock_id: int) -> int: ...
def clock_settime_ns(clock_id: int, time: int) -> int: ...

if sys.platform == "linux":
def pthread_getcpuclockid(thread_id: int) -> int: ...

def monotonic_ns() -> int: ...
def perf_counter_ns() -> int: ...
def process_time_ns() -> int: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/urllib/parse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ def urlunparse(components: Sequence[AnyStr | None]) -> AnyStr: ...
def urlunsplit(components: tuple[AnyStr | None, AnyStr | None, AnyStr | None, AnyStr | None, AnyStr | None]) -> AnyStr: ...
@overload
def urlunsplit(components: Sequence[AnyStr | None]) -> AnyStr: ...
def unwrap(url: str) -> str: ...
5 changes: 0 additions & 5 deletions tests/stubtest_allowlists/linux-py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,13 @@ os.EFD_SEMAPHORE
os.SPLICE_F_MORE
os.SPLICE_F_MOVE
os.SPLICE_F_NONBLOCK
os.copy_file_range
os.eventfd
os.eventfd_read
os.eventfd_write
os.pidfd_open
os.splice
posix.EFD_[A-Z]+
posix.SPLICE_[A-Z_]+
posix.copy_file_range
posix.eventfd
posix.eventfd_read
posix.eventfd_write
posix.pidfd_open
posix.splice
time.pthread_getcpuclockid
3 changes: 0 additions & 3 deletions tests/stubtest_allowlists/linux-py37.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
ctypes.wintypes
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
pwd.getpwnam

# Exists at runtime, but missing from stubs
time.pthread_getcpuclockid
5 changes: 0 additions & 5 deletions tests/stubtest_allowlists/linux-py38.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
select.epoll.register

# Exists at runtime, but missing from stubs
os.copy_file_range
posix.copy_file_range
time.pthread_getcpuclockid
7 changes: 0 additions & 7 deletions tests/stubtest_allowlists/linux-py39.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
(os|posix).sendfile
select.epoll.register

# Exists at runtime, but missing from stubs
os.copy_file_range
os.pidfd_open
posix.copy_file_range
posix.pidfd_open
time.pthread_getcpuclockid
3 changes: 0 additions & 3 deletions tests/stubtest_allowlists/win32-py310.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
_msi.CreateRecord
_msi.FCICreate
_msi.OpenDatabase
sqlite3.Connection.enable_load_extension
sqlite3.Connection.load_extension
sqlite3.dbapi2.Connection.enable_load_extension
Expand Down
2 changes: 0 additions & 2 deletions tests/stubtest_allowlists/win32.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ distutils.msvccompiler.MSVCCompiler.manifest_get_embed_info
distutils.msvccompiler.MSVCCompiler.manifest_setup_ldargs
distutils.msvccompiler.OldMSVCCompiler
msvcrt.SetErrorMode
os.get_handle_inheritable
os.set_handle_inheritable
socket.MsgFlag.MSG_BCAST
socket.MsgFlag.MSG_MCAST
ssl.SSLSocket.recvmsg
Expand Down