Skip to content

Backport many Self-related changes to the Python-2 stdlib #7128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/@python2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/_winreg.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from _typeshed import Self
from types import TracebackType
from typing import Any, Union

Expand Down Expand Up @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/@python2/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand All @@ -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: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/dbm/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Self
from types import TracebackType
from typing import Iterator, MutableMapping, Union
from typing_extensions import Literal
Expand All @@ -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: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/dbm/dumb.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Self
from types import TracebackType
from typing import Iterator, MutableMapping, Union

Expand All @@ -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: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/dbm/gnu.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Self
from types import TracebackType
from typing import TypeVar, Union, overload

Expand All @@ -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: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/dbm/ndbm.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Self
from types import TracebackType
from typing import TypeVar, Union, overload

Expand All @@ -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: ...
Expand Down
5 changes: 3 additions & 2 deletions stdlib/@python2/itertools.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Self
from typing import Any, Callable, Generic, Iterable, Iterator, Sequence, TypeVar, overload

_T = TypeVar("_T")
Expand All @@ -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]: ...

Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/multiprocessing/pool.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Self
from typing import Any, Callable, Iterable, Iterator

class AsyncResult:
Expand All @@ -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): ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/shelve.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections
from _typeshed import Self
from typing import Any, Iterator

class Shelf(collections.MutableMapping[Any, Any]):
Expand All @@ -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: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/sqlite3/dbapi2.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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]):
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/ssl.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/tarfile.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import io
from _typeshed import Self
from types import TracebackType
from typing import IO, Callable, Iterable, Iterator, Mapping, Text

Expand Down Expand Up @@ -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: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/tempfile.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...
Expand Down
2 changes: 2 additions & 0 deletions stdlib/@python2/thread.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
2 changes: 2 additions & 0 deletions stdlib/@python2/time.pyi
Original file line number Diff line number Diff line change
@@ -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]

Expand All @@ -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: ...
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@python2/unittest.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/zipfile.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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: ...
Expand Down