diff --git a/stdlib/asyncio/unix_events.pyi b/stdlib/asyncio/unix_events.pyi index 416049249c35..d845acf5f338 100644 --- a/stdlib/asyncio/unix_events.pyi +++ b/stdlib/asyncio/unix_events.pyi @@ -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: ... diff --git a/stdlib/concurrent/futures/_base.pyi b/stdlib/concurrent/futures/_base.pyi index ca4087948c3e..df2afb9d9b6a 100644 --- a/stdlib/concurrent/futures/_base.pyi +++ b/stdlib/concurrent/futures/_base.pyi @@ -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]]: ... diff --git a/stdlib/dbm/__init__.pyi b/stdlib/dbm/__init__.pyi index f2d64446a6a2..7344d7b1b755 100644 --- a/stdlib/dbm/__init__.pyi +++ b/stdlib/dbm/__init__.pyi @@ -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: ... diff --git a/stdlib/dbm/dumb.pyi b/stdlib/dbm/dumb.pyi index 0b8ee50a79b7..1daa24b7f5b8 100644 --- a/stdlib/dbm/dumb.pyi +++ b/stdlib/dbm/dumb.pyi @@ -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: ... diff --git a/stdlib/dbm/gnu.pyi b/stdlib/dbm/gnu.pyi index 20033ded6373..c694ca96b33f 100644 --- a/stdlib/dbm/gnu.pyi +++ b/stdlib/dbm/gnu.pyi @@ -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: ... diff --git a/stdlib/dbm/ndbm.pyi b/stdlib/dbm/ndbm.pyi index 020131543e13..6af8d5c32fd7 100644 --- a/stdlib/dbm/ndbm.pyi +++ b/stdlib/dbm/ndbm.pyi @@ -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: ... diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index e1a365737268..7258ced824b5 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -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: ... diff --git a/stdlib/telnetlib.pyi b/stdlib/telnetlib.pyi index 0ee5b760b184..9910e7cd195a 100644 --- a/stdlib/telnetlib.pyi +++ b/stdlib/telnetlib.pyi @@ -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: ... diff --git a/stdlib/tempfile.pyi b/stdlib/tempfile.pyi index f618ce1751d2..9d2fb7a5a7c5 100644 --- a/stdlib/tempfile.pyi +++ b/stdlib/tempfile.pyi @@ -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]: ... diff --git a/stdlib/winreg.pyi b/stdlib/winreg.pyi index 8f25dd61a092..ac9fcb24934b 100644 --- a/stdlib/winreg.pyi +++ b/stdlib/winreg.pyi @@ -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]: ... diff --git a/stdlib/zipfile.pyi b/stdlib/zipfile.pyi index 8f3c2bef0a68..1a6b75dd060b 100644 --- a/stdlib/zipfile.pyi +++ b/stdlib/zipfile.pyi @@ -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: ...