mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-05-04 04:25:50 +08:00
Propagate EmailMessage generics (#15639)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from email.headerregistry import Address
|
||||
from email.message import EmailMessage
|
||||
from email.headerregistry import Address, BaseHeader
|
||||
from email.message import EmailMessage, MIMEPart
|
||||
from typing_extensions import assert_type
|
||||
|
||||
msg = EmailMessage()
|
||||
@@ -8,3 +8,11 @@ msg["From"] = Address("Sender Name", "sender", "example.com")
|
||||
|
||||
for a in msg.iter_attachments():
|
||||
assert_type(a, EmailMessage)
|
||||
|
||||
generic_msg: EmailMessage[BaseHeader, str] = EmailMessage()
|
||||
assert_type(generic_msg.get("To"), BaseHeader | None)
|
||||
assert_type(generic_msg.get_body(), MIMEPart[BaseHeader, str] | None)
|
||||
for a in generic_msg.iter_attachments():
|
||||
assert_type(a, EmailMessage[BaseHeader, str])
|
||||
for p in generic_msg.iter_parts():
|
||||
assert_type(p, MIMEPart[BaseHeader, str])
|
||||
|
||||
@@ -151,13 +151,15 @@ class Message(Generic[_HeaderT_co, _HeaderParamT_contra]):
|
||||
|
||||
class MIMEPart(Message[_HeaderRegistryT_co, _HeaderRegistryParamT_contra]):
|
||||
def __init__(self, policy: Policy[Any] | None = None) -> None: ...
|
||||
def get_body(self, preferencelist: Sequence[str] = ("related", "html", "plain")) -> MIMEPart[_HeaderRegistryT_co] | None: ...
|
||||
def get_body(
|
||||
self, preferencelist: Sequence[str] = ("related", "html", "plain")
|
||||
) -> MIMEPart[_HeaderRegistryT_co, _HeaderRegistryParamT_contra] | None: ...
|
||||
def attach(self, payload: Self) -> None: ... # type: ignore[override]
|
||||
# The attachments are created via type(self) in the attach method. It's theoretically
|
||||
# possible to sneak other attachment types into a MIMEPart instance, but could cause
|
||||
# cause unforseen consequences.
|
||||
def iter_attachments(self) -> Iterator[Self]: ...
|
||||
def iter_parts(self) -> Iterator[MIMEPart[_HeaderRegistryT_co]]: ...
|
||||
def iter_parts(self) -> Iterator[MIMEPart[_HeaderRegistryT_co, _HeaderRegistryParamT_contra]]: ...
|
||||
def get_content(self, *args: Any, content_manager: ContentManager | None = None, **kw: Any) -> Any: ...
|
||||
def set_content(self, *args: Any, content_manager: ContentManager | None = None, **kw: Any) -> None: ...
|
||||
def make_related(self, boundary: str | None = None) -> None: ...
|
||||
@@ -171,4 +173,4 @@ class MIMEPart(Message[_HeaderRegistryT_co, _HeaderRegistryParamT_contra]):
|
||||
def as_string(self, unixfrom: bool = False, maxheaderlen: int | None = None, policy: Policy[Any] | None = None) -> str: ...
|
||||
def is_attachment(self) -> bool: ...
|
||||
|
||||
class EmailMessage(MIMEPart): ...
|
||||
class EmailMessage(MIMEPart[_HeaderRegistryT_co, _HeaderRegistryParamT_contra]): ...
|
||||
|
||||
Reference in New Issue
Block a user