[stdlib] Deprecate keyfile, certfile and check_hostname parameters (#15259)

This commit is contained in:
Semyon Moroz
2026-01-11 22:31:03 +00:00
committed by GitHub
parent 3593e35df4
commit a679bdc438
5 changed files with 125 additions and 28 deletions
+28 -8
View File
@@ -1,11 +1,11 @@
import sys
from _typeshed import SupportsRead, SupportsReadline
from _typeshed import StrOrBytesPath, SupportsRead, SupportsReadline
from collections.abc import Callable, Iterable, Iterator
from socket import socket
from ssl import SSLContext
from types import TracebackType
from typing import Any, Final, Literal, TextIO
from typing_extensions import Self
from typing import Any, Final, Literal, TextIO, overload
from typing_extensions import Self, deprecated
__all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto", "all_errors", "FTP_TLS"]
@@ -120,23 +120,43 @@ class FTP_TLS(FTP):
encoding: str = "utf-8",
) -> None: ...
else:
@overload
def __init__(
self,
host: str = "",
user: str = "",
passwd: str = "",
acct: str = "",
keyfile: str | None = None,
certfile: str | None = None,
keyfile: None = None,
certfile: None = None,
context: SSLContext | None = None,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
*,
encoding: str = "utf-8",
) -> None: ...
ssl_version: int
keyfile: str | None
certfile: str | None
@overload
@deprecated(
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
"removed in Python 3.12. Use `context` parameter instead."
)
def __init__(
self,
host: str = "",
user: str = "",
passwd: str = "",
acct: str = "",
keyfile: StrOrBytesPath | None = None,
certfile: StrOrBytesPath | None = None,
context: None = None,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
*,
encoding: str = "utf-8",
) -> None: ...
ssl_version: int
keyfile: StrOrBytesPath | None
certfile: StrOrBytesPath | None
context: SSLContext
def login(self, user: str = "", passwd: str = "", acct: str = "", secure: bool = True) -> str: ...
def auth(self) -> str: ...
+24 -3
View File
@@ -3,7 +3,7 @@ import io
import ssl
import sys
import types
from _typeshed import MaybeNone, ReadableBuffer, SupportsRead, SupportsReadline, WriteableBuffer
from _typeshed import MaybeNone, ReadableBuffer, StrOrBytesPath, SupportsRead, SupportsReadline, WriteableBuffer
from collections.abc import Callable, Iterable, Iterator, Mapping
from email._policybase import _MessageT
from socket import socket
@@ -223,12 +223,31 @@ class HTTPSConnection(HTTPConnection):
blocksize: int = 8192,
) -> None: ...
else:
@overload
def __init__(
self,
host: str,
port: int | None = None,
key_file: str | None = None,
cert_file: str | None = None,
key_file: None = None,
cert_file: None = None,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
*,
context: ssl.SSLContext | None = None,
check_hostname: None = None,
blocksize: int = 8192,
) -> None: ...
@overload
@deprecated(
"The `key_file`, `cert_file`, `check_hostname` parameters are deprecated since Python 3.6; "
"removed in Python 3.12. Use `context` parameter instead."
)
def __init__(
self,
host: str,
port: int | None = None,
key_file: StrOrBytesPath | None = None,
cert_file: StrOrBytesPath | None = None,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
*,
@@ -236,6 +255,8 @@ class HTTPSConnection(HTTPConnection):
check_hostname: bool | None = None,
blocksize: int = 8192,
) -> None: ...
key_file: StrOrBytesPath | None
cert_file: StrOrBytesPath | None
class HTTPException(Exception): ...
+21 -7
View File
@@ -1,7 +1,7 @@
import subprocess
import sys
import time
from _typeshed import ReadableBuffer, SizedBuffer, Unused
from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath, Unused
from builtins import list as _list # conflicts with a method named "list"
from collections.abc import Callable, Generator
from datetime import datetime
@@ -9,7 +9,7 @@ from re import Pattern
from socket import socket as _socket
from ssl import SSLContext, SSLSocket
from types import TracebackType
from typing import IO, Any, Literal, SupportsAbs, SupportsInt
from typing import IO, Any, Literal, SupportsAbs, SupportsInt, overload
from typing_extensions import Self, TypeAlias, deprecated
__all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate", "IMAP4_SSL"]
@@ -120,23 +120,37 @@ if sys.version_info >= (3, 14):
def burst(self, interval: float = 0.1) -> Generator[tuple[str, float | None]]: ...
class IMAP4_SSL(IMAP4):
if sys.version_info < (3, 12):
keyfile: str
certfile: str
if sys.version_info >= (3, 12):
def __init__(
self, host: str = "", port: int = 993, *, ssl_context: SSLContext | None = None, timeout: float | None = None
) -> None: ...
else:
@overload
def __init__(
self,
host: str = "",
port: int = 993,
keyfile: str | None = None,
certfile: str | None = None,
keyfile: None = None,
certfile: None = None,
ssl_context: SSLContext | None = None,
timeout: float | None = None,
) -> None: ...
@overload
@deprecated(
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
"removed in Python 3.12. Use `ssl_context` parameter instead."
)
def __init__(
self,
host: str = "",
port: int = 993,
keyfile: StrOrBytesPath | None = None,
certfile: StrOrBytesPath | None = None,
ssl_context: None = None,
timeout: float | None = None,
) -> None: ...
keyfile: StrOrBytesPath | None
certfile: StrOrBytesPath | None
sslobj: SSLSocket
if sys.version_info >= (3, 14):
@property
+21 -3
View File
@@ -1,10 +1,11 @@
import socket
import ssl
import sys
from _typeshed import StrOrBytesPath
from builtins import list as _list # conflicts with a method named "list"
from re import Pattern
from typing import Any, BinaryIO, Final, NoReturn, overload
from typing_extensions import TypeAlias
from typing_extensions import TypeAlias, deprecated
__all__ = ["POP3", "error_proto", "POP3_SSL"]
@@ -58,15 +59,32 @@ class POP3_SSL(POP3):
) -> None: ...
def stls(self, context: Any = None) -> NoReturn: ...
else:
@overload
def __init__(
self,
host: str,
port: int = 995,
keyfile: str | None = None,
certfile: str | None = None,
keyfile: None = None,
certfile: None = None,
timeout: float = ...,
context: ssl.SSLContext | None = None,
) -> None: ...
@overload
@deprecated(
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
"removed in Python 3.12. Use `context` parameter instead."
)
def __init__(
self,
host: str,
port: int = 995,
keyfile: StrOrBytesPath | None = None,
certfile: StrOrBytesPath | None = None,
timeout: float = ...,
context: None = None,
) -> None: ...
keyfile: StrOrBytesPath | None
certfile: StrOrBytesPath | None
# "context" is actually the last argument,
# but that breaks LSP and it doesn't really matter because all the arguments are ignored
def stls(self, context: Any = None, keyfile: Any = None, certfile: Any = None) -> NoReturn: ...
+31 -7
View File
@@ -1,6 +1,6 @@
import sys
from _socket import _Address as _SourceAddress
from _typeshed import ReadableBuffer, SizedBuffer
from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath
from collections.abc import Sequence
from email.message import Message as _Message
from re import Pattern
@@ -8,7 +8,7 @@ from socket import socket
from ssl import SSLContext
from types import TracebackType
from typing import Any, Final, Protocol, overload, type_check_only
from typing_extensions import Self, TypeAlias
from typing_extensions import Self, TypeAlias, deprecated
__all__ = [
"SMTPException",
@@ -131,8 +131,15 @@ class SMTP:
if sys.version_info >= (3, 12):
def starttls(self, *, context: SSLContext | None = None) -> _Reply: ...
else:
@overload
def starttls(self, keyfile: None = None, certfile: None = None, context: SSLContext | None = None) -> _Reply: ...
@overload
@deprecated(
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
"removed in Python 3.12. Use `context` parameter instead."
)
def starttls(
self, keyfile: str | None = None, certfile: str | None = None, context: SSLContext | None = None
self, keyfile: StrOrBytesPath | None = None, certfile: StrOrBytesPath | None = None, context: None = None
) -> _Reply: ...
def sendmail(
@@ -155,8 +162,6 @@ class SMTP:
def quit(self) -> _Reply: ...
class SMTP_SSL(SMTP):
keyfile: str | None
certfile: str | None
context: SSLContext
if sys.version_info >= (3, 12):
def __init__(
@@ -170,17 +175,36 @@ class SMTP_SSL(SMTP):
context: SSLContext | None = None,
) -> None: ...
else:
@overload
def __init__(
self,
host: str = "",
port: int = 0,
local_hostname: str | None = None,
keyfile: str | None = None,
certfile: str | None = None,
keyfile: None = None,
certfile: None = None,
timeout: float = ...,
source_address: _SourceAddress | None = None,
context: SSLContext | None = None,
) -> None: ...
@overload
@deprecated(
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
"removed in Python 3.12. Use `context` parameter instead."
)
def __init__(
self,
host: str = "",
port: int = 0,
local_hostname: str | None = None,
keyfile: StrOrBytesPath | None = None,
certfile: StrOrBytesPath | None = None,
timeout: float = ...,
source_address: _SourceAddress | None = None,
context: None = None,
) -> None: ...
keyfile: StrOrBytesPath | None
certfile: StrOrBytesPath | None
LMTP_PORT: Final = 2003