Skip to content

Commit 51cdd2c

Browse files
authored
Backport many Self-related changes to the Python-2 stdlib (#7128)
1 parent 57b2bae commit 51cdd2c

File tree

19 files changed

+37
-21
lines changed

19 files changed

+37
-21
lines changed

stdlib/@python2/__builtin__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
751751

752752
class enumerate(Iterator[tuple[int, _T]], Generic[_T]):
753753
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
754-
def __iter__(self) -> Iterator[tuple[int, _T]]: ...
754+
def __iter__(self: Self) -> Self: ...
755755
def next(self) -> tuple[int, _T]: ...
756756

757757
class xrange(Sized, Iterable[int], Reversible[int]):

stdlib/@python2/_winreg.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from _typeshed import Self
23
from types import TracebackType
34
from typing import Any, Union
45

@@ -88,7 +89,7 @@ if sys.platform == "win32":
8889
class HKEYType:
8990
def __bool__(self) -> bool: ...
9091
def __int__(self) -> int: ...
91-
def __enter__(self) -> HKEYType: ...
92+
def __enter__(self: Self) -> Self: ...
9293
def __exit__(
9394
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
9495
) -> bool | None: ...

stdlib/@python2/builtins.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
751751

752752
class enumerate(Iterator[tuple[int, _T]], Generic[_T]):
753753
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
754-
def __iter__(self) -> Iterator[tuple[int, _T]]: ...
754+
def __iter__(self: Self) -> Self: ...
755755
def next(self) -> tuple[int, _T]: ...
756756

757757
class xrange(Sized, Iterable[int], Reversible[int]):

stdlib/@python2/codecs.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
8585
def incrementaldecoder(self) -> _IncrementalDecoder: ...
8686
name: str
8787
def __new__(
88-
cls,
88+
cls: type[Self],
8989
encode: _Encoder,
9090
decode: _Decoder,
9191
streamreader: _StreamReader | None = ...,
@@ -95,7 +95,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
9595
name: str | None = ...,
9696
*,
9797
_is_text_encoding: bool | None = ...,
98-
) -> CodecInfo: ...
98+
) -> Self: ...
9999

100100
def getencoder(encoding: str) -> _Encoder: ...
101101
def getdecoder(encoding: str) -> _Decoder: ...

stdlib/@python2/dbm/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Self
12
from types import TracebackType
23
from typing import Iterator, MutableMapping, Union
34
from typing_extensions import Literal
@@ -13,7 +14,7 @@ class _Database(MutableMapping[_KeyType, bytes]):
1314
def __iter__(self) -> Iterator[bytes]: ...
1415
def __len__(self) -> int: ...
1516
def __del__(self) -> None: ...
16-
def __enter__(self) -> _Database: ...
17+
def __enter__(self: Self) -> Self: ...
1718
def __exit__(
1819
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
1920
) -> None: ...

stdlib/@python2/dbm/dumb.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Self
12
from types import TracebackType
23
from typing import Iterator, MutableMapping, Union
34

@@ -17,7 +18,7 @@ class _Database(MutableMapping[_KeyType, bytes]):
1718
def __iter__(self) -> Iterator[bytes]: ...
1819
def __len__(self) -> int: ...
1920
def __del__(self) -> None: ...
20-
def __enter__(self) -> _Database: ...
21+
def __enter__(self: Self) -> Self: ...
2122
def __exit__(
2223
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
2324
) -> None: ...

stdlib/@python2/dbm/gnu.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Self
12
from types import TracebackType
23
from typing import TypeVar, Union, overload
34

@@ -18,7 +19,7 @@ class _gdbm:
1819
def __setitem__(self, key: _KeyType, value: _ValueType) -> None: ...
1920
def __delitem__(self, key: _KeyType) -> None: ...
2021
def __len__(self) -> int: ...
21-
def __enter__(self) -> _gdbm: ...
22+
def __enter__(self: Self) -> Self: ...
2223
def __exit__(
2324
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
2425
) -> None: ...

stdlib/@python2/dbm/ndbm.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Self
12
from types import TracebackType
23
from typing import TypeVar, Union, overload
34

@@ -17,7 +18,7 @@ class _dbm:
1718
def __delitem__(self, key: _KeyType) -> None: ...
1819
def __len__(self) -> int: ...
1920
def __del__(self) -> None: ...
20-
def __enter__(self) -> _dbm: ...
21+
def __enter__(self: Self) -> Self: ...
2122
def __exit__(
2223
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
2324
) -> None: ...

stdlib/@python2/itertools.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Self
12
from typing import Any, Callable, Generic, Iterable, Iterator, Sequence, TypeVar, overload
23

34
_T = TypeVar("_T")
@@ -8,14 +9,14 @@ def count(start: int = ..., step: int = ...) -> Iterator[int]: ... # more gener
89
class cycle(Iterator[_T], Generic[_T]):
910
def __init__(self, iterable: Iterable[_T]) -> None: ...
1011
def next(self) -> _T: ...
11-
def __iter__(self) -> Iterator[_T]: ...
12+
def __iter__(self: Self) -> Self: ...
1213

1314
def repeat(object: _T, times: int = ...) -> Iterator[_T]: ...
1415

1516
class chain(Iterator[_T], Generic[_T]):
1617
def __init__(self, *iterables: Iterable[_T]) -> None: ...
1718
def next(self) -> _T: ...
18-
def __iter__(self) -> Iterator[_T]: ...
19+
def __iter__(self: Self) -> Self: ...
1920
@staticmethod
2021
def from_iterable(iterable: Iterable[Iterable[_S]]) -> Iterator[_S]: ...
2122

stdlib/@python2/multiprocessing/pool.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Self
12
from typing import Any, Callable, Iterable, Iterator
23

34
class AsyncResult:
@@ -7,7 +8,7 @@ class AsyncResult:
78
def successful(self) -> bool: ...
89

910
class IMapIterator(Iterator[Any]):
10-
def __iter__(self) -> Iterator[Any]: ...
11+
def __iter__(self: Self) -> Self: ...
1112
def next(self, timeout: float | None = ...) -> Any: ...
1213

1314
class IMapUnorderedIterator(IMapIterator): ...

0 commit comments

Comments
 (0)