From c50a708818ff17587299c9c0fa8f8f64699eb583 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 8 Sep 2023 18:42:03 +0100 Subject: [PATCH] Update `poplib` and `smtplib` for py312 (#10685) --- stdlib/poplib.pyi | 29 +++++++++------- stdlib/smtplib.pyi | 42 +++++++++++++++++------- tests/stubtest_allowlists/py310.txt | 1 + tests/stubtest_allowlists/py311.txt | 1 + tests/stubtest_allowlists/py312.txt | 3 -- tests/stubtest_allowlists/py38.txt | 1 + tests/stubtest_allowlists/py39.txt | 1 + tests/stubtest_allowlists/py3_common.txt | 1 - 8 files changed, 52 insertions(+), 27 deletions(-) diff --git a/stdlib/poplib.pyi b/stdlib/poplib.pyi index c64e47e8e..808e7e522 100644 --- a/stdlib/poplib.pyi +++ b/stdlib/poplib.pyi @@ -1,5 +1,6 @@ import socket import ssl +import sys from builtins import list as _list # conflicts with a method named "list" from re import Pattern from typing import Any, BinaryIO, NoReturn, overload @@ -51,14 +52,20 @@ class POP3: def stls(self, context: ssl.SSLContext | None = None) -> bytes: ... class POP3_SSL(POP3): - def __init__( - self, - host: str, - port: int = 995, - keyfile: str | None = None, - certfile: str | None = None, - timeout: float = ..., - context: ssl.SSLContext | None = None, - ) -> 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: ... + if sys.version_info >= (3, 12): + def __init__( + self, host: str, port: int = 995, *, timeout: float = ..., context: ssl.SSLContext | None = None + ) -> None: ... + def stls(self, context: Any = None) -> NoReturn: ... + else: + def __init__( + self, + host: str, + port: int = 995, + keyfile: str | None = None, + certfile: str | None = None, + timeout: float = ..., + context: ssl.SSLContext | None = None, + ) -> 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: ... diff --git a/stdlib/smtplib.pyi b/stdlib/smtplib.pyi index 584fa164f..e584d7f57 100644 --- a/stdlib/smtplib.pyi +++ b/stdlib/smtplib.pyi @@ -128,7 +128,13 @@ class SMTP: def auth_plain(self, challenge: ReadableBuffer | None = None) -> str: ... def auth_login(self, challenge: ReadableBuffer | None = None) -> str: ... def login(self, user: str, password: str, *, initial_response_ok: bool = True) -> _Reply: ... - def starttls(self, keyfile: str | None = None, certfile: str | None = None, context: SSLContext | None = None) -> _Reply: ... + if sys.version_info >= (3, 12): + def starttls(self, *, context: SSLContext | None = None) -> _Reply: ... + else: + def starttls( + self, keyfile: str | None = None, certfile: str | None = None, context: SSLContext | None = None + ) -> _Reply: ... + def sendmail( self, from_addr: str, @@ -152,17 +158,29 @@ class SMTP_SSL(SMTP): keyfile: str | None certfile: str | None context: SSLContext - def __init__( - self, - host: str = "", - port: int = 0, - local_hostname: str | None = None, - keyfile: str | None = None, - certfile: str | None = None, - timeout: float = ..., - source_address: _SourceAddress | None = None, - context: SSLContext | None = None, - ) -> None: ... + if sys.version_info >= (3, 12): + def __init__( + self, + host: str = "", + port: int = 0, + local_hostname: str | None = None, + *, + timeout: float = ..., + source_address: _SourceAddress | None = None, + context: SSLContext | None = None, + ) -> None: ... + else: + def __init__( + self, + host: str = "", + port: int = 0, + local_hostname: str | None = None, + keyfile: str | None = None, + certfile: str | None = None, + timeout: float = ..., + source_address: _SourceAddress | None = None, + context: SSLContext | None = None, + ) -> None: ... LMTP_PORT: int diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index d888015b2..400254ebe 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -119,6 +119,7 @@ json.encoder.i lib2to3.pgen2.grammar.line lib2to3.pgen2.grammar.name lib2to3.pgen2.grammar.op +poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi pydoc.Helper.symbol # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 pydoc.Helper.symbols_ # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 pydoc.Helper.topic # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index 2153f4e17..881fd532d 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -69,6 +69,7 @@ functools._lru_cache_wrapper.cache_parameters # Cannot be detected statically http.HTTPMethod.description # mutable instance attribute at runtime but we pretend it's a property inspect._ParameterKind.description # Still exists, but stubtest can't see it os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all PathLike classes to implement class_getitem +poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi types.GenericAlias.__call__ # Would be complicated to fix properly, Any could silence problems. #6392 types.GenericAlias.__getattr__ types.GenericAlias.__mro_entries__ diff --git a/tests/stubtest_allowlists/py312.txt b/tests/stubtest_allowlists/py312.txt index 03d66985c..737393539 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -6,9 +6,6 @@ enum.EnumType.__call__ enum.property.member http.client.HTTPConnection.get_proxy_response_headers imaplib.IMAP4_SSL.__init__ -poplib.POP3_SSL.__init__ -smtplib.SMTP.starttls -smtplib.SMTP_SSL.__init__ urllib.request.AbstractHTTPHandler.__init__ urllib.request.HTTPSHandler.__init__ diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index aba802f73..5e935b166 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -115,6 +115,7 @@ json.encoder.i lib2to3.pgen2.grammar.line lib2to3.pgen2.grammar.name lib2to3.pgen2.grammar.op +poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi pydoc.Helper.symbol # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 pydoc.Helper.symbols_ # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 pydoc.Helper.topic # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index 767da783b..d91065aef 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -95,6 +95,7 @@ json.encoder.i lib2to3.pgen2.grammar.line lib2to3.pgen2.grammar.name lib2to3.pgen2.grammar.op +poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi pydoc.Helper.symbol # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 pydoc.Helper.symbols_ # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 pydoc.Helper.topic # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index f59bc6623..1e1c357ec 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -108,7 +108,6 @@ multiprocessing.synchronize.SemLock.release numbers.Number.__hash__ # typeshed marks this as abstract but code just sets this as None optparse.Values.__getattr__ # Some attributes are set in __init__ using setattr pickle.Pickler.reducer_override # implemented in C pickler -poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi pyexpat.expat_CAPI select.poll # Depends on configuration selectors.DevpollSelector # Depends on configuration