From c7c430857eec9835cdf1b688ba4fd493ab449a81 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 11 Sep 2024 17:58:24 +0200 Subject: [PATCH] stdlib updates for latest Python patch releases (#12638) --- stdlib/@tests/stubtest_allowlists/py310.txt | 8 +++++ stdlib/@tests/stubtest_allowlists/py311.txt | 8 +++++ stdlib/@tests/stubtest_allowlists/py312.txt | 5 --- stdlib/@tests/stubtest_allowlists/py313.txt | 6 ---- stdlib/@tests/stubtest_allowlists/py38.txt | 8 +++++ stdlib/@tests/stubtest_allowlists/py39.txt | 8 +++++ stdlib/email/_header_value_parser.pyi | 4 +++ stdlib/email/_policybase.pyi | 39 ++++++++++++++------- stdlib/email/errors.pyi | 3 ++ stdlib/email/utils.pyi | 16 +++------ 10 files changed, 70 insertions(+), 35 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py310.txt b/stdlib/@tests/stubtest_allowlists/py310.txt index 8d0631cdd291..df3022652a32 100644 --- a/stdlib/@tests/stubtest_allowlists/py310.txt +++ b/stdlib/@tests/stubtest_allowlists/py310.txt @@ -259,3 +259,11 @@ tkinter.EventType.__new__ ctypes._endian.DEFAULT_MODE ctypes._endian.RTLD_GLOBAL ctypes._endian.RTLD_LOCAL + +# Incompatible changes introduced in Python 3.10.15 +# (Remove once 3.10.15 becomes available for all platforms) +(email._header_value_parser.NLSET)? +(email._header_value_parser.SPECIALSNL)? +(email.errors.HeaderWriteError)? +(email.utils.getaddresses)? +(email.utils.parseaddr)? diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index 308855f8f00b..6619a1fc7104 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -219,3 +219,11 @@ pkgutil.ImpLoader\..* ctypes._endian.DEFAULT_MODE ctypes._endian.RTLD_GLOBAL ctypes._endian.RTLD_LOCAL + +# Incompatible changes introduced in Python 3.11.10 +# (Remove once 3.11.10 becomes available for all platforms) +(email._header_value_parser.NLSET)? +(email._header_value_parser.SPECIALSNL)? +(email.errors.HeaderWriteError)? +(email.utils.getaddresses)? +(email.utils.parseaddr)? diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index 3dd734de9de7..8b02abd9621c 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -202,8 +202,3 @@ ctypes._endian.SIZEOF_TIME_T # Incompatible changes introduced in Python 3.12.5 concurrent.futures.__all__ -email._header_value_parser.NLSET -email._header_value_parser.SPECIALSNL -email._policybase.Policy.verify_generated_headers -email.errors.HeaderWriteError -email.policy.Policy.verify_generated_headers diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index a36060cd8db4..a3265d0fa587 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -191,9 +191,3 @@ codecs.xmlcharrefreplace_errors # To match `dict`, we lie about the runtime, but use overloads to match the correct behavior types.MappingProxyType.get - -# logging.warn() was restored after the 3.13 release candidate, which is what CI is using -logging.__all__ -logging.Logger.warn -logging.LoggerAdapter.warn -logging.warn diff --git a/stdlib/@tests/stubtest_allowlists/py38.txt b/stdlib/@tests/stubtest_allowlists/py38.txt index 7866e8c822b0..e66b499714df 100644 --- a/stdlib/@tests/stubtest_allowlists/py38.txt +++ b/stdlib/@tests/stubtest_allowlists/py38.txt @@ -250,3 +250,11 @@ tkinter.EventType.__new__ ctypes._endian.DEFAULT_MODE ctypes._endian.RTLD_GLOBAL ctypes._endian.RTLD_LOCAL + +# Incompatible changes introduced in Python 3.8.20 +# (Remove once 3.8.20 becomes available for GitHub Actions) +email._header_value_parser.NLSET +email._header_value_parser.SPECIALSNL +email.errors.HeaderWriteError +email.utils.getaddresses +email.utils.parseaddr diff --git a/stdlib/@tests/stubtest_allowlists/py39.txt b/stdlib/@tests/stubtest_allowlists/py39.txt index e7217a040654..0e2260452cc9 100644 --- a/stdlib/@tests/stubtest_allowlists/py39.txt +++ b/stdlib/@tests/stubtest_allowlists/py39.txt @@ -233,3 +233,11 @@ tkinter.EventType.__new__ ctypes._endian.DEFAULT_MODE ctypes._endian.RTLD_GLOBAL ctypes._endian.RTLD_LOCAL + +# Incompatible changes introduced in Python 3.9.20 +# (Remove once 3.9.20 becomes available for all platforms) +(email._header_value_parser.NLSET)? +(email._header_value_parser.SPECIALSNL)? +(email.errors.HeaderWriteError)? +(email.utils.getaddresses)? +(email.utils.parseaddr)? diff --git a/stdlib/email/_header_value_parser.pyi b/stdlib/email/_header_value_parser.pyi index 806fc84cf784..ff405a8b61d2 100644 --- a/stdlib/email/_header_value_parser.pyi +++ b/stdlib/email/_header_value_parser.pyi @@ -16,6 +16,10 @@ TOKEN_ENDS: Final[set[str]] ASPECIALS: Final[set[str]] ATTRIBUTE_ENDS: Final[set[str]] EXTENDED_ATTRIBUTE_ENDS: Final[set[str]] +# Added in Python 3.8.20, 3.9.20, 3.10.15, 3.11.10, 3.12.5 +NLSET: Final[set[str]] +# Added in Python 3.8.20, 3.9.20, 3.10.15, 3.11.10, 3.12.5 +SPECIALSNL: Final[set[str]] def quote_string(value: Any) -> str: ... diff --git a/stdlib/email/_policybase.pyi b/stdlib/email/_policybase.pyi index a3dd61a282ce..9e1f653c9d78 100644 --- a/stdlib/email/_policybase.pyi +++ b/stdlib/email/_policybase.pyi @@ -3,20 +3,9 @@ from collections.abc import Callable from email.errors import MessageDefect from email.header import Header from email.message import Message -from typing import Any from typing_extensions import Self class _PolicyBase: - def __add__(self, other: Any) -> Self: ... - def clone(self, **kw: Any) -> Self: ... - -class Policy(_PolicyBase, metaclass=ABCMeta): - max_line_length: int | None - linesep: str - cte_type: str - raise_on_defect: bool - mangle_from_: bool - message_factory: Callable[[Policy], Message] | None def __init__( self, *, @@ -24,9 +13,35 @@ class Policy(_PolicyBase, metaclass=ABCMeta): linesep: str = "\n", cte_type: str = "8bit", raise_on_defect: bool = False, - mangle_from_: bool = False, + mangle_from_: bool = ..., # default depends on sub-class message_factory: Callable[[Policy], Message] | None = None, + # Added in Python 3.8.20, 3.9.20, 3.10.15, 3.11.10, 3.12.5 + verify_generated_headers: bool = True, ) -> None: ... + def clone( + self, + *, + max_line_length: int | None = ..., + linesep: str = ..., + cte_type: str = ..., + raise_on_defect: bool = ..., + mangle_from_: bool = ..., + message_factory: Callable[[Policy], Message] | None = ..., + # Added in Python 3.8.20, 3.9.20, 3.10.15, 3.11.10, 3.12.5 + verify_generated_headers: bool = ..., + ) -> Self: ... + def __add__(self, other: Policy) -> Self: ... + +class Policy(_PolicyBase, metaclass=ABCMeta): + max_line_length: int | None + linesep: str + cte_type: str + raise_on_defect: bool + mangle_from_: bool + message_factory: Callable[[Policy], Message] | None + # Added in Python 3.8.20, 3.9.20, 3.10.15, 3.11.10, 3.12.5 + verify_generated_headers: bool + def handle_defect(self, obj: Message, defect: MessageDefect) -> None: ... def register_defect(self, obj: Message, defect: MessageDefect) -> None: ... def header_max_count(self, name: str) -> int | None: ... diff --git a/stdlib/email/errors.pyi b/stdlib/email/errors.pyi index c54f1560c9ae..f105576c5ee4 100644 --- a/stdlib/email/errors.pyi +++ b/stdlib/email/errors.pyi @@ -7,6 +7,9 @@ class BoundaryError(MessageParseError): ... class MultipartConversionError(MessageError, TypeError): ... class CharsetError(MessageError): ... +# Added in Python 3.8.20, 3.9.20, 3.10.15, 3.11.10, 3.12.5 +class HeaderWriteError(MessageError): ... + class MessageDefect(ValueError): def __init__(self, line: str | None = None) -> None: ... diff --git a/stdlib/email/utils.pyi b/stdlib/email/utils.pyi index 9dab22c18f6c..dc3eecb5ef7f 100644 --- a/stdlib/email/utils.pyi +++ b/stdlib/email/utils.pyi @@ -30,20 +30,12 @@ _PDTZ: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int | None def quote(str: str) -> str: ... def unquote(str: str) -> str: ... -if sys.version_info >= (3, 13): - def parseaddr(addr: str | list[str], *, strict: bool = True) -> tuple[str, str]: ... - -else: - def parseaddr(addr: str) -> tuple[str, str]: ... - +# `strict` parameter added in Python 3.8.20, 3.9.20, 3.10.15, 3.11.10, 3.12.5 +def parseaddr(addr: str | list[str], *, strict: bool = True) -> tuple[str, str]: ... def formataddr(pair: tuple[str | None, str], charset: str | Charset = "utf-8") -> str: ... -if sys.version_info >= (3, 13): - def getaddresses(fieldvalues: Iterable[str], *, strict: bool = True) -> list[tuple[str, str]]: ... - -else: - def getaddresses(fieldvalues: Iterable[str]) -> list[tuple[str, str]]: ... - +# `strict` parameter added in Python 3.8.20, 3.9.20, 3.10.15, 3.11.10, 3.12.5 +def getaddresses(fieldvalues: Iterable[str], *, strict: bool = True) -> list[tuple[str, str]]: ... @overload def parsedate(data: None) -> None: ... @overload