From 52e18e856ce77ffa3b5d86610124acf09348be67 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Wed, 19 Aug 2020 08:33:33 -0700 Subject: [PATCH] Added stubs for aiofiles package (#4421) --- third_party/3/aiofiles/__init__.pyi | 2 + third_party/3/aiofiles/_os.pyi | 26 ++++++ third_party/3/aiofiles/base.pyi | 34 ++++++++ .../3/aiofiles/threadpool/__init__.pyi | 80 +++++++++++++++++++ third_party/3/aiofiles/threadpool/binary.pyi | 5 ++ third_party/3/aiofiles/threadpool/text.pyi | 3 + 6 files changed, 150 insertions(+) create mode 100644 third_party/3/aiofiles/__init__.pyi create mode 100644 third_party/3/aiofiles/_os.pyi create mode 100644 third_party/3/aiofiles/base.pyi create mode 100644 third_party/3/aiofiles/threadpool/__init__.pyi create mode 100644 third_party/3/aiofiles/threadpool/binary.pyi create mode 100644 third_party/3/aiofiles/threadpool/text.pyi diff --git a/third_party/3/aiofiles/__init__.pyi b/third_party/3/aiofiles/__init__.pyi new file mode 100644 index 000000000..f943e7671 --- /dev/null +++ b/third_party/3/aiofiles/__init__.pyi @@ -0,0 +1,2 @@ +from . import _os as os +from .threadpool import open as open diff --git a/third_party/3/aiofiles/_os.pyi b/third_party/3/aiofiles/_os.pyi new file mode 100644 index 000000000..5144abe98 --- /dev/null +++ b/third_party/3/aiofiles/_os.pyi @@ -0,0 +1,26 @@ +import sys +from _typeshed import AnyPath +from os import stat_result +from typing import Optional, Sequence, Union, overload + +_FdOrAnyPath = Union[int, AnyPath] + +async def stat(path: _FdOrAnyPath, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> stat_result: ... +async def rename(src: AnyPath, dst: AnyPath, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ... +async def remove(path: AnyPath, *, dir_fd: Optional[int] = ...) -> None: ... +async def mkdir(path: AnyPath, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... +async def rmdir(path: AnyPath, *, dir_fd: Optional[int] = ...) -> None: ... + +if sys.platform != "win32": + @overload + async def sendfile(__out_fd: int, __in_fd: int, offset: Optional[int], count: int) -> int: ... + @overload + async def sendfile( + __out_fd: int, + __in_fd: int, + offset: int, + count: int, + headers: Sequence[bytes] = ..., + trailers: Sequence[bytes] = ..., + flags: int = ..., + ) -> int: ... diff --git a/third_party/3/aiofiles/base.pyi b/third_party/3/aiofiles/base.pyi new file mode 100644 index 000000000..75ba9272d --- /dev/null +++ b/third_party/3/aiofiles/base.pyi @@ -0,0 +1,34 @@ +from types import CodeType, FrameType, TracebackType, coroutine +from typing import Any, Coroutine, Generator, Generic, Iterator, Optional, Type, TypeVar, Union + +_T_co = TypeVar("_T_co", covariant=True) +_V_co = TypeVar("_V_co", covariant=True) +_T_contra = TypeVar("_T_contra", contravariant=True) + +class AsyncBase: + def __init__(self, file: str, loop: Any, executor: Any) -> None: ... + async def __aiter__(self) -> Iterator[str]: ... + async def __anext__(self) -> str: ... + +class AiofilesContextManager(Generic[_V_co, _T_co, _T_contra]): + def __init__(self, __coro: Coroutine[_V_co, _T_co, _T_contra]) -> None: ... + def send(self, __value: _T_contra) -> _T_co: ... + def throw( + self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., tb: Optional[TracebackType] = ..., + ) -> _T_co: ... + def close(self) -> None: ... + @property + def gi_frame(self) -> FrameType: ... + @property + def gi_running(self) -> bool: ... + @property + def gi_code(self) -> CodeType: ... + def __next__(self) -> _T_co: ... + @coroutine + def __iter__(self) -> Iterator[Coroutine[_V_co, _T_co, _T_contra]]: ... + def __await__(self) -> Generator[Any, None, _T_co]: ... + async def __anext__(self) -> Coroutine[_V_co, _T_co, _T_contra]: ... + async def __aenter__(self) -> Coroutine[_V_co, _T_co, _T_contra]: ... + async def __aexit__( + self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType], + ) -> None: ... diff --git a/third_party/3/aiofiles/threadpool/__init__.pyi b/third_party/3/aiofiles/threadpool/__init__.pyi new file mode 100644 index 000000000..c4d8eb9d9 --- /dev/null +++ b/third_party/3/aiofiles/threadpool/__init__.pyi @@ -0,0 +1,80 @@ +from _typeshed import AnyPath, OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode +from typing import Any, Callable, Optional, Union, overload +from typing_extensions import Literal + +from ..base import AsyncBase +from .binary import AsyncBufferedIOBase, AsyncBufferedReader, AsyncFileIO +from .text import AsyncTextIOWrapper + +_OpenFile = Union[AnyPath, int] +_Opener = Callable[[str, int], int] +@overload +def open( + file: _OpenFile, + mode: OpenTextMode = ..., + buffering: int = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + newline: Optional[str] = ..., + closefd: bool = ..., + opener: Optional[_Opener] = ..., + *, + loop: Optional[Any] = ..., + executor: Optional[Any] = ..., +) -> AsyncTextIOWrapper: ... +@overload +def open( + file: _OpenFile, + mode: OpenBinaryMode, + buffering: Literal[0], + encoding: None = ..., + errors: None = ..., + newline: None = ..., + closefd: bool = ..., + opener: Optional[_Opener] = ..., + *, + loop: Optional[Any] = ..., + executor: Optional[Any] = ..., +) -> AsyncFileIO: ... +@overload +def open( + file: _OpenFile, + mode: OpenBinaryModeWriting, + buffering: Literal[-1, 1] = ..., + encoding: None = ..., + errors: None = ..., + newline: None = ..., + closefd: bool = ..., + opener: Optional[_Opener] = ..., + *, + loop: Optional[Any] = ..., + executor: Optional[Any] = ..., +) -> AsyncBufferedIOBase: ... +@overload +def open( + file: _OpenFile, + mode: Union[OpenBinaryModeReading, OpenBinaryModeUpdating], + buffering: Literal[-1, 1] = ..., + encoding: None = ..., + errors: None = ..., + newline: None = ..., + closefd: bool = ..., + opener: Optional[_Opener] = ..., + *, + loop: Optional[Any] = ..., + executor: Optional[Any] = ..., +) -> AsyncBufferedReader: ... +@overload +def open( + file: _OpenFile, + mode: OpenBinaryMode, + buffering: int, + encoding: None = ..., + errors: None = ..., + newline: None = ..., + closefd: bool = ..., + opener: Optional[_Opener] = ..., + *, + loop: Optional[Any] = ..., + executor: Optional[Any] = ..., +) -> AsyncBase: ... diff --git a/third_party/3/aiofiles/threadpool/binary.pyi b/third_party/3/aiofiles/threadpool/binary.pyi new file mode 100644 index 000000000..909c9d2ea --- /dev/null +++ b/third_party/3/aiofiles/threadpool/binary.pyi @@ -0,0 +1,5 @@ +from ..base import AsyncBase + +class AsyncBufferedIOBase(AsyncBase): ... +class AsyncBufferedReader(AsyncBufferedIOBase): ... +class AsyncFileIO(AsyncBase): ... diff --git a/third_party/3/aiofiles/threadpool/text.pyi b/third_party/3/aiofiles/threadpool/text.pyi new file mode 100644 index 000000000..fcd8f2df8 --- /dev/null +++ b/third_party/3/aiofiles/threadpool/text.pyi @@ -0,0 +1,3 @@ +from ..base import AsyncBase + +class AsyncTextIOWrapper(AsyncBase): ...