mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-06 21:43:59 +08:00
Don't require IO for redirect_stdout (#14905)
This commit is contained in:
+15
-6
@@ -4,7 +4,7 @@ from _typeshed import FileDescriptorOrPath, Unused
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator
|
||||
from types import TracebackType
|
||||
from typing import IO, Any, Generic, Protocol, TypeVar, overload, runtime_checkable, type_check_only
|
||||
from typing import Any, Generic, Protocol, TypeVar, overload, runtime_checkable, type_check_only
|
||||
from typing_extensions import ParamSpec, Self, TypeAlias
|
||||
|
||||
__all__ = [
|
||||
@@ -30,7 +30,6 @@ if sys.version_info >= (3, 11):
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_T_co = TypeVar("_T_co", covariant=True)
|
||||
_T_io = TypeVar("_T_io", bound=IO[str] | None)
|
||||
_ExitT_co = TypeVar("_ExitT_co", covariant=True, bound=bool | None, default=bool | None)
|
||||
_F = TypeVar("_F", bound=Callable[..., Any])
|
||||
_G_co = TypeVar("_G_co", bound=Generator[Any, Any, Any] | AsyncGenerator[Any, Any], covariant=True)
|
||||
@@ -141,14 +140,24 @@ class suppress(AbstractContextManager[None, bool]):
|
||||
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
|
||||
) -> bool: ...
|
||||
|
||||
class _RedirectStream(AbstractContextManager[_T_io, None]):
|
||||
def __init__(self, new_target: _T_io) -> None: ...
|
||||
# This is trying to describe what is needed for (most?) uses
|
||||
# of `redirect_stdout` and `redirect_stderr`.
|
||||
# https://github.com/python/typeshed/issues/14903
|
||||
@type_check_only
|
||||
class _SupportsRedirect(Protocol):
|
||||
def write(self, s: str, /) -> int: ...
|
||||
def flush(self) -> None: ...
|
||||
|
||||
_SupportsRedirectT = TypeVar("_SupportsRedirectT", bound=_SupportsRedirect | None)
|
||||
|
||||
class _RedirectStream(AbstractContextManager[_SupportsRedirectT, None]):
|
||||
def __init__(self, new_target: _SupportsRedirectT) -> None: ...
|
||||
def __exit__(
|
||||
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
class redirect_stdout(_RedirectStream[_T_io]): ...
|
||||
class redirect_stderr(_RedirectStream[_T_io]): ...
|
||||
class redirect_stdout(_RedirectStream[_SupportsRedirectT]): ...
|
||||
class redirect_stderr(_RedirectStream[_SupportsRedirectT]): ...
|
||||
|
||||
class _BaseExitStack(Generic[_ExitT_co]):
|
||||
def enter_context(self, cm: AbstractContextManager[_T, _ExitT_co]) -> _T: ...
|
||||
|
||||
Reference in New Issue
Block a user