Skip to content

Commit 58559e5

Browse files
authored
Use _typeshed.Self where __enter__ returns self (#5698)
1 parent 1fb100d commit 58559e5

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

stdlib/aifc.pyi

Lines changed: 3 additions & 2 deletions
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 IO, Any, List, NamedTuple, Optional, Tuple, Type, Union, overload
45
from typing_extensions import Literal
@@ -18,7 +19,7 @@ _Marker = Tuple[int, int, bytes]
1819

1920
class Aifc_read:
2021
def __init__(self, f: _File) -> None: ...
21-
def __enter__(self) -> Aifc_read: ...
22+
def __enter__(self: Self) -> Self: ...
2223
def __exit__(
2324
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
2425
) -> None: ...
@@ -42,7 +43,7 @@ class Aifc_read:
4243
class Aifc_write:
4344
def __init__(self, f: _File) -> None: ...
4445
def __del__(self) -> None: ...
45-
def __enter__(self) -> Aifc_write: ...
46+
def __enter__(self: Self) -> Self: ...
4647
def __exit__(
4748
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
4849
) -> None: ...

stdlib/asyncio/windows_utils.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 Callable, Optional, Protocol, Tuple, Type
45

@@ -18,7 +19,7 @@ class PipeHandle:
1819
def __del__(self, _warn: _WarnFunction = ...) -> None: ...
1920
else:
2021
def __del__(self) -> None: ...
21-
def __enter__(self) -> PipeHandle: ...
22+
def __enter__(self: Self) -> Self: ...
2223
def __exit__(self, t: Optional[type], v: Optional[BaseException], tb: Optional[TracebackType]) -> None: ...
2324
@property
2425
def handle(self) -> int: ...

stdlib/imaplib.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import subprocess
22
import sys
33
import time
4+
from _typeshed import Self
45
from socket import socket as _socket
56
from ssl import SSLContext, SSLSocket
67
from types import TracebackType
@@ -59,7 +60,7 @@ class IMAP4:
5960
def delete(self, mailbox: str) -> _CommandResults: ...
6061
def deleteacl(self, mailbox: str, who: str) -> _CommandResults: ...
6162
def enable(self, capability: str) -> _CommandResults: ...
62-
def __enter__(self) -> IMAP4: ...
63+
def __enter__(self: Self) -> Self: ...
6364
def __exit__(self, t: Optional[Type[BaseException]], v: Optional[BaseException], tb: Optional[TracebackType]) -> None: ...
6465
def expunge(self) -> _CommandResults: ...
6566
def fetch(self, message_set: str, message_parts: str) -> Tuple[str, _AnyResponseData]: ...

stdlib/multiprocessing/connection.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import socket
22
import sys
33
import types
4+
from _typeshed import Self
45
from typing import Any, Iterable, List, Optional, Tuple, Type, Union
56

67
if sys.version_info >= (3, 8):
@@ -48,7 +49,7 @@ class Listener:
4849
def address(self) -> _Address: ...
4950
@property
5051
def last_accepted(self) -> Optional[_Address]: ...
51-
def __enter__(self) -> Listener: ...
52+
def __enter__(self: Self) -> Self: ...
5253
def __exit__(
5354
self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], exc_tb: Optional[types.TracebackType]
5455
) -> None: ...

stdlib/shelve.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import collections.abc
2+
from _typeshed import Self
23
from typing import Any, Dict, Iterator, Optional, Tuple
34

45
class Shelf(collections.abc.MutableMapping[Any, Any]):
@@ -12,7 +13,7 @@ class Shelf(collections.abc.MutableMapping[Any, Any]):
1213
def __getitem__(self, key: str) -> Any: ...
1314
def __setitem__(self, key: str, value: Any) -> None: ...
1415
def __delitem__(self, key: str) -> None: ...
15-
def __enter__(self) -> Shelf: ...
16+
def __enter__(self: Self) -> Self: ...
1617
def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...
1718
def close(self) -> None: ...
1819
def __del__(self) -> None: ...

stdlib/smtplib.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 email.message import Message as _Message
23
from socket import socket
34
from ssl import SSLContext
@@ -75,7 +76,7 @@ class SMTP:
7576
timeout: float = ...,
7677
source_address: Optional[_SourceAddress] = ...,
7778
) -> None: ...
78-
def __enter__(self) -> SMTP: ...
79+
def __enter__(self: Self) -> Self: ...
7980
def __exit__(
8081
self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], tb: Optional[TracebackType]
8182
) -> None: ...

stdlib/wave.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from _typeshed import Self
23
from typing import IO, Any, BinaryIO, NamedTuple, NoReturn, Optional, Union
34

45
_File = Union[str, IO[bytes]]
@@ -17,7 +18,7 @@ class _wave_params(NamedTuple):
1718

1819
class Wave_read:
1920
def __init__(self, f: _File) -> None: ...
20-
def __enter__(self) -> Wave_read: ...
21+
def __enter__(self: Self) -> Self: ...
2122
def __exit__(self, *args: Any) -> None: ...
2223
def getfp(self) -> Optional[BinaryIO]: ...
2324
def rewind(self) -> None: ...
@@ -37,7 +38,7 @@ class Wave_read:
3738

3839
class Wave_write:
3940
def __init__(self, f: _File) -> None: ...
40-
def __enter__(self) -> Wave_write: ...
41+
def __enter__(self: Self) -> Self: ...
4142
def __exit__(self, *args: Any) -> None: ...
4243
def setnchannels(self, nchannels: int) -> None: ...
4344
def getnchannels(self) -> int: ...

0 commit comments

Comments
 (0)