From ef15088d651f98f963785ebe400ca92f160de3e3 Mon Sep 17 00:00:00 2001 From: Pavel Karateev Date: Mon, 31 May 2021 20:24:53 +0300 Subject: [PATCH] Add encoding & errors parameters to fileinput (#5558) --- stdlib/fileinput.pyi | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/stdlib/fileinput.pyi b/stdlib/fileinput.pyi index ed07ebecd..0fd7937e1 100644 --- a/stdlib/fileinput.pyi +++ b/stdlib/fileinput.pyi @@ -1,8 +1,20 @@ import sys from _typeshed import StrOrBytesPath -from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Optional, Union +from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Union -if sys.version_info >= (3, 8): +if sys.version_info >= (3, 10): + def input( + files: Union[StrOrBytesPath, Iterable[StrOrBytesPath], None] = ..., + inplace: bool = ..., + backup: str = ..., + *, + mode: str = ..., + openhook: Callable[[StrOrBytesPath, str], IO[AnyStr]] = ..., + encoding: str | None = ..., + errors: str | None = ..., + ) -> FileInput[AnyStr]: ... + +elif sys.version_info >= (3, 8): def input( files: Union[StrOrBytesPath, Iterable[StrOrBytesPath], None] = ..., inplace: bool = ..., @@ -32,7 +44,19 @@ def isfirstline() -> bool: ... def isstdin() -> bool: ... class FileInput(Iterable[AnyStr], Generic[AnyStr]): - if sys.version_info >= (3, 8): + if sys.version_info >= (3, 10): + def __init__( + self, + files: Union[None, StrOrBytesPath, Iterable[StrOrBytesPath]] = ..., + inplace: bool = ..., + backup: str = ..., + *, + mode: str = ..., + openhook: Callable[[StrOrBytesPath, str], IO[AnyStr]] = ..., + encoding: str | None = ..., + errors: str | None = ..., + ) -> None: ... + elif sys.version_info >= (3, 8): def __init__( self, files: Union[None, StrOrBytesPath, Iterable[StrOrBytesPath]] = ..., @@ -68,5 +92,12 @@ class FileInput(Iterable[AnyStr], Generic[AnyStr]): def isfirstline(self) -> bool: ... def isstdin(self) -> bool: ... -def hook_compressed(filename: StrOrBytesPath, mode: str) -> IO[Any]: ... -def hook_encoded(encoding: str, errors: Optional[str] = ...) -> Callable[[StrOrBytesPath, str], IO[Any]]: ... +if sys.version_info >= (3, 10): + def hook_compressed( + filename: StrOrBytesPath, mode: str, *, encoding: str | None = ..., errors: str | None = ... + ) -> IO[Any]: ... + +else: + def hook_compressed(filename: StrOrBytesPath, mode: str) -> IO[Any]: ... + +def hook_encoded(encoding: str, errors: str | None = ...) -> Callable[[StrOrBytesPath, str], IO[Any]]: ...