Skip to content

Commit a679bdc

Browse files
authored
[stdlib] Deprecate keyfile, certfile and check_hostname parameters (#15259)
1 parent 3593e35 commit a679bdc

File tree

5 files changed

+125
-28
lines changed

5 files changed

+125
-28
lines changed

stdlib/ftplib.pyi

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import sys
2-
from _typeshed import SupportsRead, SupportsReadline
2+
from _typeshed import StrOrBytesPath, SupportsRead, SupportsReadline
33
from collections.abc import Callable, Iterable, Iterator
44
from socket import socket
55
from ssl import SSLContext
66
from types import TracebackType
7-
from typing import Any, Final, Literal, TextIO
8-
from typing_extensions import Self
7+
from typing import Any, Final, Literal, TextIO, overload
8+
from typing_extensions import Self, deprecated
99

1010
__all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto", "all_errors", "FTP_TLS"]
1111

@@ -120,23 +120,43 @@ class FTP_TLS(FTP):
120120
encoding: str = "utf-8",
121121
) -> None: ...
122122
else:
123+
@overload
123124
def __init__(
124125
self,
125126
host: str = "",
126127
user: str = "",
127128
passwd: str = "",
128129
acct: str = "",
129-
keyfile: str | None = None,
130-
certfile: str | None = None,
130+
keyfile: None = None,
131+
certfile: None = None,
131132
context: SSLContext | None = None,
132133
timeout: float | None = ...,
133134
source_address: tuple[str, int] | None = None,
134135
*,
135136
encoding: str = "utf-8",
136137
) -> None: ...
137-
ssl_version: int
138-
keyfile: str | None
139-
certfile: str | None
138+
@overload
139+
@deprecated(
140+
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
141+
"removed in Python 3.12. Use `context` parameter instead."
142+
)
143+
def __init__(
144+
self,
145+
host: str = "",
146+
user: str = "",
147+
passwd: str = "",
148+
acct: str = "",
149+
keyfile: StrOrBytesPath | None = None,
150+
certfile: StrOrBytesPath | None = None,
151+
context: None = None,
152+
timeout: float | None = ...,
153+
source_address: tuple[str, int] | None = None,
154+
*,
155+
encoding: str = "utf-8",
156+
) -> None: ...
157+
ssl_version: int
158+
keyfile: StrOrBytesPath | None
159+
certfile: StrOrBytesPath | None
140160
context: SSLContext
141161
def login(self, user: str = "", passwd: str = "", acct: str = "", secure: bool = True) -> str: ...
142162
def auth(self) -> str: ...

stdlib/http/client.pyi

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import io
33
import ssl
44
import sys
55
import types
6-
from _typeshed import MaybeNone, ReadableBuffer, SupportsRead, SupportsReadline, WriteableBuffer
6+
from _typeshed import MaybeNone, ReadableBuffer, StrOrBytesPath, SupportsRead, SupportsReadline, WriteableBuffer
77
from collections.abc import Callable, Iterable, Iterator, Mapping
88
from email._policybase import _MessageT
99
from socket import socket
@@ -223,19 +223,40 @@ class HTTPSConnection(HTTPConnection):
223223
blocksize: int = 8192,
224224
) -> None: ...
225225
else:
226+
@overload
226227
def __init__(
227228
self,
228229
host: str,
229230
port: int | None = None,
230-
key_file: str | None = None,
231-
cert_file: str | None = None,
231+
key_file: None = None,
232+
cert_file: None = None,
233+
timeout: float | None = ...,
234+
source_address: tuple[str, int] | None = None,
235+
*,
236+
context: ssl.SSLContext | None = None,
237+
check_hostname: None = None,
238+
blocksize: int = 8192,
239+
) -> None: ...
240+
@overload
241+
@deprecated(
242+
"The `key_file`, `cert_file`, `check_hostname` parameters are deprecated since Python 3.6; "
243+
"removed in Python 3.12. Use `context` parameter instead."
244+
)
245+
def __init__(
246+
self,
247+
host: str,
248+
port: int | None = None,
249+
key_file: StrOrBytesPath | None = None,
250+
cert_file: StrOrBytesPath | None = None,
232251
timeout: float | None = ...,
233252
source_address: tuple[str, int] | None = None,
234253
*,
235254
context: ssl.SSLContext | None = None,
236255
check_hostname: bool | None = None,
237256
blocksize: int = 8192,
238257
) -> None: ...
258+
key_file: StrOrBytesPath | None
259+
cert_file: StrOrBytesPath | None
239260

240261
class HTTPException(Exception): ...
241262

stdlib/imaplib.pyi

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import subprocess
22
import sys
33
import time
4-
from _typeshed import ReadableBuffer, SizedBuffer, Unused
4+
from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath, Unused
55
from builtins import list as _list # conflicts with a method named "list"
66
from collections.abc import Callable, Generator
77
from datetime import datetime
88
from re import Pattern
99
from socket import socket as _socket
1010
from ssl import SSLContext, SSLSocket
1111
from types import TracebackType
12-
from typing import IO, Any, Literal, SupportsAbs, SupportsInt
12+
from typing import IO, Any, Literal, SupportsAbs, SupportsInt, overload
1313
from typing_extensions import Self, TypeAlias, deprecated
1414

1515
__all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate", "IMAP4_SSL"]
@@ -120,23 +120,37 @@ if sys.version_info >= (3, 14):
120120
def burst(self, interval: float = 0.1) -> Generator[tuple[str, float | None]]: ...
121121

122122
class IMAP4_SSL(IMAP4):
123-
if sys.version_info < (3, 12):
124-
keyfile: str
125-
certfile: str
126123
if sys.version_info >= (3, 12):
127124
def __init__(
128125
self, host: str = "", port: int = 993, *, ssl_context: SSLContext | None = None, timeout: float | None = None
129126
) -> None: ...
130127
else:
128+
@overload
131129
def __init__(
132130
self,
133131
host: str = "",
134132
port: int = 993,
135-
keyfile: str | None = None,
136-
certfile: str | None = None,
133+
keyfile: None = None,
134+
certfile: None = None,
137135
ssl_context: SSLContext | None = None,
138136
timeout: float | None = None,
139137
) -> None: ...
138+
@overload
139+
@deprecated(
140+
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
141+
"removed in Python 3.12. Use `ssl_context` parameter instead."
142+
)
143+
def __init__(
144+
self,
145+
host: str = "",
146+
port: int = 993,
147+
keyfile: StrOrBytesPath | None = None,
148+
certfile: StrOrBytesPath | None = None,
149+
ssl_context: None = None,
150+
timeout: float | None = None,
151+
) -> None: ...
152+
keyfile: StrOrBytesPath | None
153+
certfile: StrOrBytesPath | None
140154
sslobj: SSLSocket
141155
if sys.version_info >= (3, 14):
142156
@property

stdlib/poplib.pyi

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import socket
22
import ssl
33
import sys
4+
from _typeshed import StrOrBytesPath
45
from builtins import list as _list # conflicts with a method named "list"
56
from re import Pattern
67
from typing import Any, BinaryIO, Final, NoReturn, overload
7-
from typing_extensions import TypeAlias
8+
from typing_extensions import TypeAlias, deprecated
89

910
__all__ = ["POP3", "error_proto", "POP3_SSL"]
1011

@@ -58,15 +59,32 @@ class POP3_SSL(POP3):
5859
) -> None: ...
5960
def stls(self, context: Any = None) -> NoReturn: ...
6061
else:
62+
@overload
6163
def __init__(
6264
self,
6365
host: str,
6466
port: int = 995,
65-
keyfile: str | None = None,
66-
certfile: str | None = None,
67+
keyfile: None = None,
68+
certfile: None = None,
6769
timeout: float = ...,
6870
context: ssl.SSLContext | None = None,
6971
) -> None: ...
72+
@overload
73+
@deprecated(
74+
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
75+
"removed in Python 3.12. Use `context` parameter instead."
76+
)
77+
def __init__(
78+
self,
79+
host: str,
80+
port: int = 995,
81+
keyfile: StrOrBytesPath | None = None,
82+
certfile: StrOrBytesPath | None = None,
83+
timeout: float = ...,
84+
context: None = None,
85+
) -> None: ...
86+
keyfile: StrOrBytesPath | None
87+
certfile: StrOrBytesPath | None
7088
# "context" is actually the last argument,
7189
# but that breaks LSP and it doesn't really matter because all the arguments are ignored
7290
def stls(self, context: Any = None, keyfile: Any = None, certfile: Any = None) -> NoReturn: ...

stdlib/smtplib.pyi

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import sys
22
from _socket import _Address as _SourceAddress
3-
from _typeshed import ReadableBuffer, SizedBuffer
3+
from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath
44
from collections.abc import Sequence
55
from email.message import Message as _Message
66
from re import Pattern
77
from socket import socket
88
from ssl import SSLContext
99
from types import TracebackType
1010
from typing import Any, Final, Protocol, overload, type_check_only
11-
from typing_extensions import Self, TypeAlias
11+
from typing_extensions import Self, TypeAlias, deprecated
1212

1313
__all__ = [
1414
"SMTPException",
@@ -131,8 +131,15 @@ class SMTP:
131131
if sys.version_info >= (3, 12):
132132
def starttls(self, *, context: SSLContext | None = None) -> _Reply: ...
133133
else:
134+
@overload
135+
def starttls(self, keyfile: None = None, certfile: None = None, context: SSLContext | None = None) -> _Reply: ...
136+
@overload
137+
@deprecated(
138+
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
139+
"removed in Python 3.12. Use `context` parameter instead."
140+
)
134141
def starttls(
135-
self, keyfile: str | None = None, certfile: str | None = None, context: SSLContext | None = None
142+
self, keyfile: StrOrBytesPath | None = None, certfile: StrOrBytesPath | None = None, context: None = None
136143
) -> _Reply: ...
137144

138145
def sendmail(
@@ -155,8 +162,6 @@ class SMTP:
155162
def quit(self) -> _Reply: ...
156163

157164
class SMTP_SSL(SMTP):
158-
keyfile: str | None
159-
certfile: str | None
160165
context: SSLContext
161166
if sys.version_info >= (3, 12):
162167
def __init__(
@@ -170,17 +175,36 @@ class SMTP_SSL(SMTP):
170175
context: SSLContext | None = None,
171176
) -> None: ...
172177
else:
178+
@overload
173179
def __init__(
174180
self,
175181
host: str = "",
176182
port: int = 0,
177183
local_hostname: str | None = None,
178-
keyfile: str | None = None,
179-
certfile: str | None = None,
184+
keyfile: None = None,
185+
certfile: None = None,
180186
timeout: float = ...,
181187
source_address: _SourceAddress | None = None,
182188
context: SSLContext | None = None,
183189
) -> None: ...
190+
@overload
191+
@deprecated(
192+
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
193+
"removed in Python 3.12. Use `context` parameter instead."
194+
)
195+
def __init__(
196+
self,
197+
host: str = "",
198+
port: int = 0,
199+
local_hostname: str | None = None,
200+
keyfile: StrOrBytesPath | None = None,
201+
certfile: StrOrBytesPath | None = None,
202+
timeout: float = ...,
203+
source_address: _SourceAddress | None = None,
204+
context: None = None,
205+
) -> None: ...
206+
keyfile: StrOrBytesPath | None
207+
certfile: StrOrBytesPath | None
184208

185209
LMTP_PORT: Final = 2003
186210

0 commit comments

Comments
 (0)