--- /home/ncoghlan/devel/contextlib2/dev/typeshed_contextlib.pyi 2024-05-23 12:40:10.170754997 +1000 +++ /home/ncoghlan/devel/contextlib2/contextlib2/__init__.pyi 2024-05-23 16:47:15.874656809 +1000 @@ -1,3 +1,20 @@ +# Type hints copied from the typeshed project under the Apache License 2.0 +# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE + +# For updates: https://github.com/python/typeshed/blob/main/stdlib/contextlib.pyi + +# Last updated: 2024-05-22 +# Updated from: https://github.com/python/typeshed/blob/aa2d33df211e1e4f70883388febf750ac524d2bb/stdlib/contextlib.pyi +# Saved to: dev/typeshed_contextlib.pyi + +# contextlib2 API adaptation notes: +# * the various 'if True:' guards replace sys.version checks in the original +# typeshed file (those APIs are available on all supported versions) +# * any commented out 'if True:' guards replace sys.version checks in the original +# typeshed file where the affected APIs haven't been backported yet +# * deliberately omitted APIs are listed in `dev/mypy.allowlist` +# (e.g. deprecated experimental APIs that never graduated to the stdlib) + import abc import sys from _typeshed import FileDescriptorOrPath, Unused @@ -22,10 +39,10 @@ "nullcontext", ] -if sys.version_info >= (3, 10): +if True: __all__ += ["aclosing"] -if sys.version_info >= (3, 11): +if True: __all__ += ["chdir"] _T = TypeVar("_T") @@ -65,18 +82,14 @@ func: Callable[..., Generator[_T_co, Any, Any]] args: tuple[Any, ...] kwds: dict[str, Any] - if sys.version_info >= (3, 9): + if True: def __exit__( self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... - else: - def __exit__( - self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None - ) -> bool | None: ... def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ... -if sys.version_info >= (3, 10): +if True: _AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]]) class AsyncContextDecorator: @@ -94,17 +107,6 @@ self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... -else: - class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co, bool | None]): - def __init__(self, func: Callable[..., AsyncIterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ... - gen: AsyncGenerator[_T_co, Any] - func: Callable[..., AsyncGenerator[_T_co, Any]] - args: tuple[Any, ...] - kwds: dict[str, Any] - async def __aexit__( - self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None - ) -> bool | None: ... - def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... class _SupportsClose(Protocol): @@ -116,7 +118,7 @@ def __init__(self, thing: _SupportsCloseT) -> None: ... def __exit__(self, *exc_info: Unused) -> None: ... -if sys.version_info >= (3, 10): +if True: class _SupportsAclose(Protocol): def aclose(self) -> Awaitable[object]: ... @@ -177,7 +179,7 @@ self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None, / ) -> bool: ... -if sys.version_info >= (3, 10): +if True: class nullcontext(AbstractContextManager[_T, None], AbstractAsyncContextManager[_T, None]): enter_result: _T @overload @@ -189,17 +191,7 @@ async def __aenter__(self) -> _T: ... async def __aexit__(self, *exctype: Unused) -> None: ... -else: - class nullcontext(AbstractContextManager[_T, None]): - enter_result: _T - @overload - def __init__(self: nullcontext[None], enter_result: None = None) -> None: ... - @overload - def __init__(self: nullcontext[_T], enter_result: _T) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 - def __enter__(self) -> _T: ... - def __exit__(self, *exctype: Unused) -> None: ... - -if sys.version_info >= (3, 11): +if True: _T_fd_or_any_path = TypeVar("_T_fd_or_any_path", bound=FileDescriptorOrPath) class chdir(AbstractContextManager[None, None], Generic[_T_fd_or_any_path]):