Use _typeshed.Self with __enter__ (#5723)

Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
Anton Grübel
2021-07-04 20:10:01 +02:00
committed by GitHub
parent 1a131a489e
commit d68701c0ec
10 changed files with 32 additions and 22 deletions

View File

@@ -29,7 +29,7 @@ class _ConnectionBase:
def recv_bytes_into(self, buf: Any, offset: int = ...) -> int: ...
def recv(self) -> Any: ...
def poll(self, timeout: Optional[float] = ...) -> bool: ...
def __enter__(self) -> _ConnectionBase: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], exc_tb: Optional[types.TracebackType]
) -> None: ...

View File

@@ -1,11 +1,10 @@
from _typeshed import Self
from queue import Queue
from types import TracebackType
from typing import Any, List, Optional, Tuple, Type, TypeVar, Union
from typing import Any, List, Optional, Tuple, Type, Union
families: List[None]
_ConnectionT = TypeVar("_ConnectionT", bound=Connection)
_ListenerT = TypeVar("_ListenerT", bound=Listener)
_Address = Union[str, Tuple[str, int]]
class Connection(object):
@@ -15,7 +14,7 @@ class Connection(object):
recv_bytes: Any
send: Any
send_bytes: Any
def __enter__(self: _ConnectionT) -> _ConnectionT: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> None: ...
@@ -27,7 +26,7 @@ class Listener(object):
_backlog_queue: Optional[Queue[Any]]
@property
def address(self) -> Optional[Queue[Any]]: ...
def __enter__(self: _ListenerT) -> _ListenerT: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> None: ...

View File

@@ -1,4 +1,5 @@
import sys
from _typeshed import Self
from typing import Any, Callable, ContextManager, Generic, Iterable, Iterator, List, Mapping, Optional, TypeVar
if sys.version_info >= (3, 9):
@@ -77,7 +78,7 @@ class Pool(ContextManager[Pool]):
def close(self) -> None: ...
def terminate(self) -> None: ...
def join(self) -> None: ...
def __enter__(self: _PT) -> _PT: ...
def __enter__(self: Self) -> Self: ...
class ThreadPool(Pool, ContextManager[ThreadPool]):
def __init__(