diff --git a/stdlib/@python2/__builtin__.pyi b/stdlib/@python2/__builtin__.pyi index d5e1c2e5e53b..0039adaaacb3 100644 --- a/stdlib/@python2/__builtin__.pyi +++ b/stdlib/@python2/__builtin__.pyi @@ -751,7 +751,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]): class enumerate(Iterator[tuple[int, _T]], Generic[_T]): def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... - def __iter__(self) -> Iterator[tuple[int, _T]]: ... + def __iter__(self: Self) -> Self: ... def next(self) -> tuple[int, _T]: ... class xrange(Sized, Iterable[int], Reversible[int]): diff --git a/stdlib/@python2/_winreg.pyi b/stdlib/@python2/_winreg.pyi index 0381dc03ba01..e432d883e4d5 100644 --- a/stdlib/@python2/_winreg.pyi +++ b/stdlib/@python2/_winreg.pyi @@ -1,4 +1,5 @@ import sys +from _typeshed import Self from types import TracebackType from typing import Any, Union @@ -88,7 +89,7 @@ if sys.platform == "win32": class HKEYType: def __bool__(self) -> bool: ... def __int__(self) -> int: ... - def __enter__(self) -> HKEYType: ... + def __enter__(self: Self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> bool | None: ... diff --git a/stdlib/@python2/builtins.pyi b/stdlib/@python2/builtins.pyi index d5e1c2e5e53b..0039adaaacb3 100644 --- a/stdlib/@python2/builtins.pyi +++ b/stdlib/@python2/builtins.pyi @@ -751,7 +751,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]): class enumerate(Iterator[tuple[int, _T]], Generic[_T]): def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... - def __iter__(self) -> Iterator[tuple[int, _T]]: ... + def __iter__(self: Self) -> Self: ... def next(self) -> tuple[int, _T]: ... class xrange(Sized, Iterable[int], Reversible[int]): diff --git a/stdlib/@python2/codecs.pyi b/stdlib/@python2/codecs.pyi index 339578ca1ae7..2780d473b781 100644 --- a/stdlib/@python2/codecs.pyi +++ b/stdlib/@python2/codecs.pyi @@ -85,7 +85,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]): def incrementaldecoder(self) -> _IncrementalDecoder: ... name: str def __new__( - cls, + cls: type[Self], encode: _Encoder, decode: _Decoder, streamreader: _StreamReader | None = ..., @@ -95,7 +95,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]): name: str | None = ..., *, _is_text_encoding: bool | None = ..., - ) -> CodecInfo: ... + ) -> Self: ... def getencoder(encoding: str) -> _Encoder: ... def getdecoder(encoding: str) -> _Decoder: ... diff --git a/stdlib/@python2/dbm/__init__.pyi b/stdlib/@python2/dbm/__init__.pyi index 738c60792a4e..9c867074df06 100644 --- a/stdlib/@python2/dbm/__init__.pyi +++ b/stdlib/@python2/dbm/__init__.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from types import TracebackType from typing import Iterator, MutableMapping, Union from typing_extensions import Literal @@ -13,7 +14,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: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/@python2/dbm/dumb.pyi b/stdlib/@python2/dbm/dumb.pyi index 163ceb53d685..e040f23ce2b0 100644 --- a/stdlib/@python2/dbm/dumb.pyi +++ b/stdlib/@python2/dbm/dumb.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from types import TracebackType from typing import Iterator, MutableMapping, 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: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/@python2/dbm/gnu.pyi b/stdlib/@python2/dbm/gnu.pyi index b8b10cb62b3e..1eecfac66a5f 100644 --- a/stdlib/@python2/dbm/gnu.pyi +++ b/stdlib/@python2/dbm/gnu.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from types import TracebackType from typing import TypeVar, Union, overload @@ -18,7 +19,7 @@ class _gdbm: def __setitem__(self, key: _KeyType, value: _ValueType) -> None: ... def __delitem__(self, key: _KeyType) -> None: ... def __len__(self) -> int: ... - def __enter__(self) -> _gdbm: ... + def __enter__(self: Self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/@python2/dbm/ndbm.pyi b/stdlib/@python2/dbm/ndbm.pyi index dec50baaaaf4..12d9f31881c1 100644 --- a/stdlib/@python2/dbm/ndbm.pyi +++ b/stdlib/@python2/dbm/ndbm.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from types import TracebackType from typing import 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: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/@python2/itertools.pyi b/stdlib/@python2/itertools.pyi index c16ca8debb03..6509213e1625 100644 --- a/stdlib/@python2/itertools.pyi +++ b/stdlib/@python2/itertools.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from typing import Any, Callable, Generic, Iterable, Iterator, Sequence, TypeVar, overload _T = TypeVar("_T") @@ -8,14 +9,14 @@ def count(start: int = ..., step: int = ...) -> Iterator[int]: ... # more gener class cycle(Iterator[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T]) -> None: ... def next(self) -> _T: ... - def __iter__(self) -> Iterator[_T]: ... + def __iter__(self: Self) -> Self: ... def repeat(object: _T, times: int = ...) -> Iterator[_T]: ... class chain(Iterator[_T], Generic[_T]): def __init__(self, *iterables: Iterable[_T]) -> None: ... def next(self) -> _T: ... - def __iter__(self) -> Iterator[_T]: ... + def __iter__(self: Self) -> Self: ... @staticmethod def from_iterable(iterable: Iterable[Iterable[_S]]) -> Iterator[_S]: ... diff --git a/stdlib/@python2/multiprocessing/pool.pyi b/stdlib/@python2/multiprocessing/pool.pyi index 3a1245fe1b7f..440b5e83c500 100644 --- a/stdlib/@python2/multiprocessing/pool.pyi +++ b/stdlib/@python2/multiprocessing/pool.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from typing import Any, Callable, Iterable, Iterator class AsyncResult: @@ -7,7 +8,7 @@ class AsyncResult: def successful(self) -> bool: ... class IMapIterator(Iterator[Any]): - def __iter__(self) -> Iterator[Any]: ... + def __iter__(self: Self) -> Self: ... def next(self, timeout: float | None = ...) -> Any: ... class IMapUnorderedIterator(IMapIterator): ... diff --git a/stdlib/@python2/shelve.pyi b/stdlib/@python2/shelve.pyi index 0e795c4148a7..011159792e60 100644 --- a/stdlib/@python2/shelve.pyi +++ b/stdlib/@python2/shelve.pyi @@ -1,4 +1,5 @@ import collections +from _typeshed import Self from typing import Any, Iterator class Shelf(collections.MutableMapping[Any, Any]): @@ -14,7 +15,7 @@ class Shelf(collections.MutableMapping[Any, Any]): def __getitem__(self, key: Any) -> Any: ... def __setitem__(self, key: Any, value: Any) -> None: ... def __delitem__(self, key: Any) -> None: ... - def __enter__(self) -> Shelf: ... + def __enter__(self: Self) -> Self: ... def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... def close(self) -> None: ... def __del__(self) -> None: ... diff --git a/stdlib/@python2/sqlite3/dbapi2.pyi b/stdlib/@python2/sqlite3/dbapi2.pyi index 37b3b6df71b0..90740bcf90a1 100644 --- a/stdlib/@python2/sqlite3/dbapi2.pyi +++ b/stdlib/@python2/sqlite3/dbapi2.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from datetime import date, datetime, time from typing import Any, Callable, Generator, Iterable, Iterator, Protocol, Text, TypeVar @@ -126,7 +127,7 @@ class Connection(object): def enable_load_extension(self, enabled: bool) -> None: ... def load_extension(self, path: str) -> None: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ... - def __enter__(self) -> Connection: ... + def __enter__(self: Self) -> Self: ... def __exit__(self, t: type | None, exc: BaseException | None, tb: Any | None) -> None: ... class Cursor(Iterator[Any]): diff --git a/stdlib/@python2/ssl.pyi b/stdlib/@python2/ssl.pyi index 67ba3bb18bdd..4eccf5875d55 100644 --- a/stdlib/@python2/ssl.pyi +++ b/stdlib/@python2/ssl.pyi @@ -1,6 +1,6 @@ import socket import sys -from _typeshed import StrPath +from _typeshed import Self, StrPath from typing import Any, Callable, ClassVar, Iterable, NamedTuple, Optional, Text, Union, overload from typing_extensions import Literal @@ -213,7 +213,7 @@ class SSLSocket(socket.socket): class SSLContext: check_hostname: bool options: int - def __new__(cls, protocol: int, *args: Any, **kwargs: Any) -> SSLContext: ... + def __new__(cls: type[Self], protocol: int, *args: Any, **kwargs: Any) -> Self: ... @property def protocol(self) -> int: ... verify_flags: int diff --git a/stdlib/@python2/tarfile.pyi b/stdlib/@python2/tarfile.pyi index 4f1efe5e4070..571bb19632a8 100644 --- a/stdlib/@python2/tarfile.pyi +++ b/stdlib/@python2/tarfile.pyi @@ -1,4 +1,5 @@ import io +from _typeshed import Self from types import TracebackType from typing import IO, Callable, Iterable, Iterator, Mapping, Text @@ -103,7 +104,7 @@ class TarFile(Iterable[TarInfo]): errorlevel: int | None = ..., copybufsize: int | None = ..., # undocumented ) -> None: ... - def __enter__(self) -> TarFile: ... + def __enter__(self: Self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/@python2/tempfile.pyi b/stdlib/@python2/tempfile.pyi index 25397d130165..3d94bdefeb74 100644 --- a/stdlib/@python2/tempfile.pyi +++ b/stdlib/@python2/tempfile.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from random import Random from thread import LockType from typing import IO, Any, AnyStr, Iterable, Iterator, Text, overload @@ -23,7 +24,7 @@ class _TemporaryFileWrapper(IO[str]): name: Any def __init__(self, file: IO[str], name: Any, delete: bool = ...) -> None: ... def __del__(self) -> None: ... - def __enter__(self) -> _TemporaryFileWrapper: ... + def __enter__(self: Self) -> Self: ... def __exit__(self, exc, value, tb) -> bool | None: ... def __getattr__(self, name: unicode) -> Any: ... def close(self) -> None: ... diff --git a/stdlib/@python2/thread.pyi b/stdlib/@python2/thread.pyi index b3ba062a498e..9823dddcbfd7 100644 --- a/stdlib/@python2/thread.pyi +++ b/stdlib/@python2/thread.pyi @@ -1,9 +1,11 @@ from typing import Any, Callable +from typing_extensions import final def _count() -> int: ... class error(Exception): ... +@final class LockType: def acquire(self, waitflag: int = ...) -> bool: ... def acquire_lock(self, waitflag: int = ...) -> bool: ... diff --git a/stdlib/@python2/time.pyi b/stdlib/@python2/time.pyi index cbe5d63017b0..93cdafa7cafa 100644 --- a/stdlib/@python2/time.pyi +++ b/stdlib/@python2/time.pyi @@ -1,5 +1,6 @@ import sys from typing import Any, NamedTuple +from typing_extensions import final _TimeTuple = tuple[int, int, int, int, int, int, int, int, int] @@ -26,6 +27,7 @@ class _struct_time(NamedTuple): @property def n_unnamed_fields(self) -> int: ... +@final class struct_time(_struct_time): def __init__(self, o: _TimeTuple, _arg: Any = ...) -> None: ... def __new__(cls, o: _TimeTuple, _arg: Any = ...) -> struct_time: ... diff --git a/stdlib/@python2/unittest.pyi b/stdlib/@python2/unittest.pyi index 5a3084c391f6..9db413d996bb 100644 --- a/stdlib/@python2/unittest.pyi +++ b/stdlib/@python2/unittest.pyi @@ -1,5 +1,6 @@ import datetime import types +from _typeshed import Self from abc import ABCMeta, abstractmethod from typing import Any, Callable, Iterable, Iterator, Mapping, NoReturn, Pattern, Sequence, Text, TextIO, TypeVar, Union, overload from typing_extensions import ParamSpec @@ -54,7 +55,7 @@ class _AssertRaisesBaseContext: class _AssertRaisesContext(_AssertRaisesBaseContext): exception: Any - def __enter__(self) -> _AssertRaisesContext: ... + def __enter__(self: Self) -> Self: ... def __exit__(self, exc_type, exc_value, tb) -> bool: ... class TestCase(Testable): diff --git a/stdlib/@python2/zipfile.pyi b/stdlib/@python2/zipfile.pyi index b5db240bd89e..0f376d2d93b8 100644 --- a/stdlib/@python2/zipfile.pyi +++ b/stdlib/@python2/zipfile.pyi @@ -1,5 +1,5 @@ import io -from _typeshed import StrPath +from _typeshed import Self, StrPath from types import TracebackType from typing import IO, Any, Callable, Iterable, Pattern, Protocol, Sequence, Text, Union @@ -46,7 +46,7 @@ class ZipFile: NameToInfo: dict[Text, ZipInfo] start_dir: int # undocumented def __init__(self, file: StrPath | IO[bytes], mode: Text = ..., compression: int = ..., allowZip64: bool = ...) -> None: ... - def __enter__(self) -> ZipFile: ... + def __enter__(self: Self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ...