Use _typeshed.Self with __enter__ (#5719)

This commit is contained in:
Anton Grübel
2021-07-01 23:15:13 +02:00
committed by GitHub
parent 96e0660fba
commit 8a107464a8
11 changed files with 30 additions and 45 deletions

View File

@@ -1,22 +1,19 @@
import sys
import types
from _typeshed import Self
from socket import socket
from typing import Any, Callable, Optional, Type, TypeVar
from typing import Any, Callable, Optional, Type
from .base_events import Server
from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy, _ProtocolFactory, _SSLContext
from .selector_events import BaseSelectorEventLoop
_T1 = TypeVar("_T1", bound=AbstractChildWatcher)
_T2 = TypeVar("_T2", bound=SafeChildWatcher)
_T3 = TypeVar("_T3", bound=FastChildWatcher)
class AbstractChildWatcher:
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
def remove_child_handler(self, pid: int) -> bool: ...
def attach_loop(self, loop: Optional[AbstractEventLoop]) -> None: ...
def close(self) -> None: ...
def __enter__(self: _T1) -> _T1: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType]
) -> None: ...
@@ -27,10 +24,10 @@ class BaseChildWatcher(AbstractChildWatcher):
def __init__(self) -> None: ...
class SafeChildWatcher(BaseChildWatcher):
def __enter__(self: _T2) -> _T2: ...
def __enter__(self: Self) -> Self: ...
class FastChildWatcher(BaseChildWatcher):
def __enter__(self: _T3) -> _T3: ...
def __enter__(self: Self) -> Self: ...
class _UnixSelectorEventLoop(BaseSelectorEventLoop):
if sys.version_info < (3, 7):
@@ -55,15 +52,12 @@ DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy
if sys.version_info >= (3, 8):
from typing import Protocol
_T4 = TypeVar("_T4", bound=MultiLoopChildWatcher)
_T5 = TypeVar("_T5", bound=ThreadedChildWatcher)
class _Warn(Protocol):
def __call__(
self, message: str, category: Optional[Type[Warning]] = ..., stacklevel: int = ..., source: Optional[Any] = ...
) -> None: ...
class MultiLoopChildWatcher(AbstractChildWatcher):
def __enter__(self: _T4) -> _T4: ...
def __enter__(self: Self) -> Self: ...
class ThreadedChildWatcher(AbstractChildWatcher):
def __enter__(self: _T5) -> _T5: ...
def __enter__(self: Self) -> Self: ...
def __del__(self, _warn: _Warn = ...) -> None: ...

View File

@@ -1,5 +1,6 @@
import sys
import threading
from _typeshed import Self
from abc import abstractmethod
from logging import Logger
from typing import (
@@ -79,7 +80,7 @@ class Executor:
def shutdown(self, wait: bool = ..., *, cancel_futures: bool = ...) -> None: ...
else:
def shutdown(self, wait: bool = ...) -> None: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Optional[bool]: ...
def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ...

View File

@@ -1,3 +1,4 @@
from _typeshed import Self
from types import TracebackType
from typing import Iterator, MutableMapping, Optional, Tuple, Type, Union
from typing_extensions import Literal
@@ -79,7 +80,7 @@ class _Database(MutableMapping[_KeyType, bytes]):
def __iter__(self) -> Iterator[bytes]: ...
def __len__(self) -> int: ...
def __del__(self) -> None: ...
def __enter__(self) -> _Database: ...
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,3 +1,4 @@
from _typeshed import Self
from types import TracebackType
from typing import Iterator, MutableMapping, Optional, Type, Union
@@ -17,7 +18,7 @@ class _Database(MutableMapping[_KeyType, bytes]):
def __iter__(self) -> Iterator[bytes]: ...
def __len__(self) -> int: ...
def __del__(self) -> None: ...
def __enter__(self) -> _Database: ...
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,3 +1,4 @@
from _typeshed import Self
from types import TracebackType
from typing import List, Optional, Type, TypeVar, Union, overload
@@ -19,7 +20,7 @@ class _gdbm:
def __delitem__(self, key: _KeyType) -> None: ...
def __contains__(self, key: _KeyType) -> bool: ...
def __len__(self) -> int: ...
def __enter__(self) -> _gdbm: ...
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,3 +1,4 @@
from _typeshed import Self
from types import TracebackType
from typing import List, Optional, Type, TypeVar, Union, overload
@@ -17,7 +18,7 @@ class _dbm:
def __delitem__(self, key: _KeyType) -> None: ...
def __len__(self) -> int: ...
def __del__(self) -> None: ...
def __enter__(self) -> _dbm: ...
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,7 +1,7 @@
import bz2
import io
import sys
from _typeshed import StrOrBytesPath, StrPath
from _typeshed import Self, StrOrBytesPath, StrPath
from collections.abc import Callable, Iterable, Iterator, Mapping
from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj
from types import TracebackType
@@ -124,7 +124,7 @@ class TarFile:
errorlevel: Optional[int] = ...,
copybufsize: Optional[int] = ..., # undocumented
) -> None: ...
def __enter__(self: _TF) -> _TF: ...
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 socket
from _typeshed import Self
from typing import Any, Callable, Match, Optional, Pattern, Sequence, Tuple, Union
DEBUGLEVEL: int
@@ -109,5 +110,5 @@ class Telnet:
def expect(
self, list: Sequence[Union[Pattern[bytes], bytes]], timeout: Optional[float] = ...
) -> Tuple[int, Optional[Match[bytes]], bytes]: ...
def __enter__(self) -> Telnet: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...

View File

@@ -1,7 +1,8 @@
import os
import sys
from _typeshed import Self
from types import TracebackType
from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, List, Optional, Tuple, Type, TypeVar, Union, overload
from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, List, Optional, Tuple, Type, Union, overload
from typing_extensions import Literal
if sys.version_info >= (3, 9):
@@ -12,7 +13,6 @@ TMP_MAX: int
tempdir: Optional[str]
template: str
_S = TypeVar("_S")
_DirT = Union[AnyStr, os.PathLike[AnyStr]]
if sys.version_info >= (3, 8):
@@ -168,7 +168,7 @@ class _TemporaryFileWrapper(Generic[AnyStr], IO[AnyStr]):
name: str
delete: bool
def __init__(self, file: IO[AnyStr], name: str, delete: bool = ...) -> None: ...
def __enter__(self) -> _TemporaryFileWrapper[AnyStr]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType]
) -> Optional[bool]: ...
@@ -289,7 +289,7 @@ class SpooledTemporaryFile(IO[AnyStr]):
dir: Optional[str] = ...,
) -> None: ...
def rollover(self) -> None: ...
def __enter__(self: _S) -> _S: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> Optional[bool]: ...

View File

@@ -1,3 +1,4 @@
from _typeshed import Self
from types import TracebackType
from typing import Any, Optional, Tuple, Type, Union
@@ -90,7 +91,7 @@ error = OSError
class HKEYType:
def __bool__(self) -> bool: ...
def __int__(self) -> int: ...
def __enter__(self) -> HKEYType: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> Optional[bool]: ...

View File

@@ -1,26 +1,10 @@
import io
import sys
from _typeshed import StrPath
from _typeshed import Self, StrPath
from types import TracebackType
from typing import (
IO,
Callable,
Dict,
Iterable,
Iterator,
List,
Optional,
Protocol,
Sequence,
Tuple,
Type,
TypeVar,
Union,
overload,
)
from typing import IO, Callable, Dict, Iterable, Iterator, List, Optional, Protocol, Sequence, Tuple, Type, Union, overload
from typing_extensions import Literal
_T = TypeVar("_T")
_DateTuple = Tuple[int, int, int, int, int, int]
class BadZipFile(Exception): ...
@@ -144,7 +128,7 @@ class ZipFile:
def __init__(
self, file: Union[StrPath, IO[bytes]], mode: str = ..., compression: int = ..., allowZip64: bool = ...
) -> None: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> None: ...