Clean up and fix email message types (#13532)

* Unify the `_MessageT` type var in `email._policybase`.
* Use explicit type arguments for `Message` type in `_MessageT` type var.
  In particular, change bound from `Message[str, str]` to `Message[Any, Any]`.
* Change `__init__()` overloads of `Parser` and `BytesParser` to accept
  `Message` objects that are not `Message[str, str]` if `_class` is not also given.
This commit is contained in:
Sebastian Rittau
2025-05-05 11:59:51 -04:00
committed by GitHub
parent a43e0a4c02
commit 0eb44e574c
11 changed files with 42 additions and 25 deletions
+3 -5
View File
@@ -1,14 +1,12 @@
from collections.abc import Callable
from email._policybase import Compat32 as Compat32, Policy as Policy, _MessageFactory, compat32 as compat32
from email._policybase import Compat32 as Compat32, Policy as Policy, _MessageFactory, _MessageT, compat32 as compat32
from email.contentmanager import ContentManager
from email.message import EmailMessage, Message
from typing import Any, TypeVar, overload
from email.message import EmailMessage
from typing import Any, overload
from typing_extensions import Self
__all__ = ["Compat32", "compat32", "Policy", "EmailPolicy", "default", "strict", "SMTP", "HTTP"]
_MessageT = TypeVar("_MessageT", bound=Message, default=Message)
class EmailPolicy(Policy[_MessageT]):
utf8: bool
refold_source: str