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

@@ -3,7 +3,7 @@ import io
import ssl
import sys
import types
from _typeshed import WriteableBuffer
from _typeshed import Self, WriteableBuffer
from socket import socket
from typing import (
IO,
@@ -115,7 +115,7 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO):
def fileno(self) -> int: ...
def isclosed(self) -> bool: ...
def __iter__(self) -> Iterator[bytes]: ...
def __enter__(self) -> HTTPResponse: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[types.TracebackType]
) -> Optional[bool]: ...

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__(

View File

@@ -6,6 +6,7 @@ from _typeshed import (
OpenBinaryModeUpdating,
OpenBinaryModeWriting,
OpenTextMode,
Self,
StrOrBytesPath,
StrPath,
)
@@ -860,7 +861,7 @@ if sys.version_info >= (3, 8):
path: Optional[str]
def __init__(self, path: Optional[str], cookie: _T, remove_dll_directory: Callable[[_T], Any]) -> None: ...
def close(self) -> None: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def add_dll_directory(path: str) -> _AddedDllDirectory: ...
if sys.platform == "linux":

View File

@@ -1,5 +1,5 @@
import sys
from _typeshed import StrOrBytesPath
from _typeshed import Self, StrOrBytesPath
from datetime import date, datetime, time
from typing import Any, Callable, Generator, Iterable, Iterator, List, Optional, Protocol, Tuple, Type, TypeVar, Union
@@ -158,7 +158,7 @@ class Connection(object):
sleep: float = ...,
) -> None: ...
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
def __enter__(self) -> Connection: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, t: Optional[type], exc: Optional[BaseException], tb: Optional[Any]) -> None: ...
class Cursor(Iterator[Any]):

View File

@@ -2,6 +2,7 @@ import datetime
import logging
import sys
import unittest.result
from _typeshed import Self
from collections.abc import Set
from types import TracebackType
from typing import (
@@ -14,6 +15,7 @@ from typing import (
Iterable,
List,
Mapping,
NamedTuple,
NoReturn,
Optional,
Pattern,
@@ -251,9 +253,13 @@ class FunctionTestCase(TestCase):
) -> None: ...
def runTest(self) -> None: ...
class _LoggingWatcher(NamedTuple):
records: List[logging.LogRecord]
output: List[str]
class _AssertRaisesContext(Generic[_E]):
exception: _E
def __enter__(self) -> _AssertRaisesContext[_E]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> bool: ...
@@ -265,7 +271,7 @@ class _AssertWarnsContext:
filename: str
lineno: int
warnings: List[WarningMessage]
def __enter__(self) -> _AssertWarnsContext: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> None: ...
@@ -275,7 +281,10 @@ class _AssertLogsContext:
records: List[logging.LogRecord]
output: List[str]
def __init__(self, test_case: TestCase, logger_name: str, level: int) -> None: ...
def __enter__(self) -> _AssertLogsContext: ...
if sys.version_info >= (3, 10):
def __enter__(self) -> _LoggingWatcher | None: ...
else:
def __enter__(self) -> _LoggingWatcher: ...
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 email.message import Message
from types import TracebackType
from typing import IO, Any, BinaryIO, Callable, Iterable, List, Optional, Tuple, Type, TypeVar
@@ -7,7 +8,7 @@ _AIUT = TypeVar("_AIUT", bound=addbase)
class addbase(BinaryIO):
fp: IO[bytes]
def __init__(self, fp: IO[bytes]) -> None: ...
def __enter__(self: _AIUT) -> _AIUT: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]
) -> None: ...

View File

@@ -1,11 +1,10 @@
import sys
import xml.dom
from typing import IO, Any, Optional, TypeVar, Union
from _typeshed import Self
from typing import IO, Any, Optional, Union
from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS
from xml.sax.xmlreader import XMLReader
_T = TypeVar("_T")
def parse(file: Union[str, IO[Any]], parser: Optional[XMLReader] = ..., bufsize: Optional[int] = ...): ...
def parseString(string: Union[str, bytes], parser: Optional[XMLReader] = ...): ...
def getDOMImplementation(features=...): ...
@@ -39,7 +38,7 @@ class Node(xml.dom.Node):
def setUserData(self, key, data, handler): ...
childNodes: Any
def unlink(self) -> None: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, et, ev, tb) -> None: ...
class DocumentFragment(Node):

View File

@@ -2,7 +2,7 @@ import gzip
import http.client
import sys
import time
from _typeshed import SupportsRead, SupportsWrite
from _typeshed import Self, SupportsRead, SupportsWrite
from datetime import datetime
from io import BytesIO
from types import TracebackType
@@ -301,7 +301,7 @@ class ServerProxy:
def __call__(self, attr: Literal["transport"]) -> Transport: ...
@overload
def __call__(self, attr: str) -> Union[Callable[[], None], Transport]: ...
def __enter__(self) -> ServerProxy: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> None: ...