From a6919227be0084a780e2e9c81c9dcce50dc5f07a Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 31 Jan 2023 01:21:39 +0000 Subject: [PATCH] Add several version-dependent default values to parameters in the stdlib (#9631) --- stdlib/builtins.pyi | 6 ++++-- stdlib/codecs.pyi | 15 ++++++++++++--- stdlib/distutils/log.pyi | 2 +- stdlib/shutil.pyi | 7 ++++++- stdlib/tarfile.pyi | 6 +++++- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 1344e5368..e635a6e57 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -849,8 +849,10 @@ class memoryview(Sequence[int]): def __setitem__(self, __s: slice, __o: ReadableBuffer) -> None: ... @overload def __setitem__(self, __i: SupportsIndex, __o: SupportsIndex) -> None: ... - if sys.version_info >= (3, 8): - def tobytes(self, order: Literal["C", "F", "A"] | None = ...) -> bytes: ... + if sys.version_info >= (3, 10): + def tobytes(self, order: Literal["C", "F", "A"] | None = "C") -> bytes: ... + elif sys.version_info >= (3, 8): + def tobytes(self, order: Literal["C", "F", "A"] | None = None) -> bytes: ... else: def tobytes(self) -> bytes: ... diff --git a/stdlib/codecs.pyi b/stdlib/codecs.pyi index 7f852906c..33d0e6709 100644 --- a/stdlib/codecs.pyi +++ b/stdlib/codecs.pyi @@ -1,3 +1,4 @@ +import sys import types from _codecs import * from _typeshed import ReadableBuffer, Self @@ -127,9 +128,17 @@ def getincrementalencoder(encoding: str) -> _IncrementalEncoder: ... def getincrementaldecoder(encoding: str) -> _IncrementalDecoder: ... def getreader(encoding: str) -> _StreamReader: ... def getwriter(encoding: str) -> _StreamWriter: ... -def open( - filename: str, mode: str = "r", encoding: str | None = None, errors: str = "strict", buffering: int = ... -) -> StreamReaderWriter: ... + +if sys.version_info >= (3, 8): + def open( + filename: str, mode: str = "r", encoding: str | None = None, errors: str = "strict", buffering: int = -1 + ) -> StreamReaderWriter: ... + +else: + def open( + filename: str, mode: str = "r", encoding: str | None = None, errors: str = "strict", buffering: int = 1 + ) -> StreamReaderWriter: ... + def EncodedFile(file: _Stream, data_encoding: str, file_encoding: str | None = None, errors: str = "strict") -> StreamRecoder: ... def iterencode(iterator: Iterable[str], encoding: str, errors: str = "strict") -> Generator[bytes, None, None]: ... def iterdecode(iterator: Iterable[bytes], encoding: str, errors: str = "strict") -> Generator[str, None, None]: ... diff --git a/stdlib/distutils/log.pyi b/stdlib/distutils/log.pyi index 549b569e7..14ed8d8ae 100644 --- a/stdlib/distutils/log.pyi +++ b/stdlib/distutils/log.pyi @@ -7,7 +7,7 @@ ERROR: int FATAL: int class Log: - def __init__(self, threshold: int = ...) -> None: ... + def __init__(self, threshold: int = 3) -> None: ... def log(self, level: int, msg: str, *args: Any) -> None: ... def debug(self, msg: str, *args: Any) -> None: ... def info(self, msg: str, *args: Any) -> None: ... diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index b0714690e..0e4f521e5 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -47,7 +47,12 @@ class ExecError(OSError): ... class ReadError(OSError): ... class RegistryError(Exception): ... -def copyfileobj(fsrc: SupportsRead[AnyStr], fdst: SupportsWrite[AnyStr], length: int = ...) -> None: ... +if sys.version_info >= (3, 8): + def copyfileobj(fsrc: SupportsRead[AnyStr], fdst: SupportsWrite[AnyStr], length: int = 0) -> None: ... + +else: + def copyfileobj(fsrc: SupportsRead[AnyStr], fdst: SupportsWrite[AnyStr], length: int = 16384) -> None: ... + def copyfile(src: StrOrBytesPath, dst: _StrOrBytesPathT, *, follow_symlinks: bool = True) -> _StrOrBytesPathT: ... def copymode(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = True) -> None: ... def copystat(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = True) -> None: ... diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 873a2b635..0aca7956a 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -354,7 +354,11 @@ class TarInfo: @linkpath.setter def linkpath(self, linkname: str) -> None: ... def get_info(self) -> Mapping[str, str | int | bytes | Mapping[str, str]]: ... - def tobuf(self, format: int | None = ..., encoding: str | None = "utf-8", errors: str = "surrogateescape") -> bytes: ... + if sys.version_info >= (3, 8): + def tobuf(self, format: int | None = 2, encoding: str | None = "utf-8", errors: str = "surrogateescape") -> bytes: ... + else: + def tobuf(self, format: int | None = 1, encoding: str | None = "utf-8", errors: str = "surrogateescape") -> bytes: ... + def create_ustar_header( self, info: Mapping[str, str | int | bytes | Mapping[str, str]], encoding: str, errors: str ) -> bytes: ...