From 5dcca3fe468b63d23579b6816fcab3b3e63da3be Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 19 Dec 2021 22:38:08 +0000 Subject: [PATCH] Improve stubs for `email.policy` (#6631) * Add the ABCMeta metaclass, present at runtime. * Add missing attributes from the allowlist, which are documented. * Annotate the __init__ methods according to the documentation. --- stdlib/email/policy.pyi | 32 +++++++++++++++++++++--- tests/stubtest_allowlists/py3_common.txt | 4 --- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/stdlib/email/policy.pyi b/stdlib/email/policy.pyi index 1c813cb96..15991c7e0 100644 --- a/stdlib/email/policy.pyi +++ b/stdlib/email/policy.pyi @@ -1,17 +1,27 @@ -from abc import abstractmethod +from abc import ABCMeta, abstractmethod from email.contentmanager import ContentManager from email.errors import MessageDefect from email.header import Header from email.message import Message from typing import Any, Callable -class Policy: +class Policy(metaclass=ABCMeta): max_line_length: int | None linesep: str cte_type: str raise_on_defect: bool - mange_from: bool - def __init__(self, **kw: Any) -> None: ... + mangle_from_: bool + message_factory: Callable[[Policy], Message] | None + def __init__( + self, + *, + max_line_length: int | None = ..., + linesep: str = ..., + cte_type: str = ..., + raise_on_defect: bool = ..., + mangle_from_: bool = ..., + message_factory: Callable[[Policy], Message] | None = ..., + ) -> None: ... def clone(self, **kw: Any) -> Policy: ... def handle_defect(self, obj: Message, defect: MessageDefect) -> None: ... def register_defect(self, obj: Message, defect: MessageDefect) -> None: ... @@ -41,6 +51,20 @@ class EmailPolicy(Policy): refold_source: str header_factory: Callable[[str, str], str] content_manager: ContentManager + def __init__( + self, + *, + max_line_length: int | None = ..., + linesep: str = ..., + cte_type: str = ..., + raise_on_defect: bool = ..., + mangle_from_: bool = ..., + message_factory: Callable[[Policy], Message] | None = ..., + utf8: bool = ..., + refold_source: str = ..., + header_factory: Callable[[str, str], str] = ..., + content_manager: ContentManager = ..., + ) -> None: ... def header_source_parse(self, sourcelines: list[str]) -> tuple[str, str]: ... def header_store_parse(self, name: str, value: str) -> tuple[str, str]: ... def header_fetch_parse(self, name: str, value: str) -> str: ... diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 10d3b729c..f8eb61238 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -585,10 +585,6 @@ email.message.Message.raw_items email.message.Message.set_raw email.mime email.parser -email.policy.Compat32.mangle_from_ -email.policy.EmailPolicy.message_factory -email.policy.Policy.mangle_from_ -email.policy.Policy.message_factory email.quoprimime email.utils importlib.abc.Finder.find_module