Skip to content

Commit

Permalink
stdlib updates for latest Python patch releases (#12638)
Browse files Browse the repository at this point in the history
  • Loading branch information
srittau authored Sep 11, 2024
1 parent 9d6fc1d commit c7c4308
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 35 deletions.
8 changes: 8 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
8 changes: 8 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
5 changes: 0 additions & 5 deletions stdlib/@tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions stdlib/@tests/stubtest_allowlists/py313.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py38.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
4 changes: 4 additions & 0 deletions stdlib/email/_header_value_parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

Expand Down
39 changes: 27 additions & 12 deletions stdlib/email/_policybase.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,45 @@ 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,
*,
max_line_length: int | None = 78,
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: ...
Expand Down
3 changes: 3 additions & 0 deletions stdlib/email/errors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

Expand Down
16 changes: 4 additions & 12 deletions stdlib/email/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c7c4308

Please sign in to comment.