Skip to content

Commit 4c5c576

Browse files
authored
email.message: Allow any header value (#11574)
1 parent 579d208 commit 4c5c576

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

stdlib/email/message.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ _PayloadType: TypeAlias = Message | str
1515
_EncodedPayloadType: TypeAlias = Message | bytes
1616
_MultipartPayloadType: TypeAlias = list[_PayloadType]
1717
_CharsetType: TypeAlias = Charset | str | None
18-
# Type returned by Policy.header_fetch_parse, AnyOf[str | Header]
18+
# Type returned by Policy.header_fetch_parse, often str or Header.
1919
_HeaderType: TypeAlias = Any
20-
_HeaderTypeParam: TypeAlias = str | Header
20+
# Type accepted by Policy.header_store_parse.
21+
_HeaderTypeParam: TypeAlias = str | Header | Any
2122

2223
class _SupportsEncodeToPayload(Protocol):
2324
def encode(self, encoding: str, /) -> _PayloadType | _MultipartPayloadType | _SupportsDecodeToPayload: ...
2425

2526
class _SupportsDecodeToPayload(Protocol):
2627
def decode(self, encoding: str, errors: str, /) -> _PayloadType | _MultipartPayloadType: ...
2728

29+
# TODO: This class should be generic over the header policy and/or the header
30+
# value types allowed by the policy. This depends on PEP 696 support
31+
# (https://github.com/python/typeshed/issues/11422).
2832
class Message:
2933
policy: Policy # undocumented
3034
preamble: str | None
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from email.headerregistry import Address
2+
from email.message import EmailMessage
3+
4+
msg = EmailMessage()
5+
msg["To"] = "[email protected]"
6+
msg["From"] = Address("Sender Name", "sender", "example.com")

0 commit comments

Comments
 (0)