mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-07-12 03:10:52 +08:00
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:
@@ -0,0 +1,16 @@
|
||||
import email.policy
|
||||
from email.message import EmailMessage, Message
|
||||
from email.parser import BytesParser, Parser
|
||||
from typing_extensions import assert_type
|
||||
|
||||
p1 = Parser()
|
||||
p2 = Parser(policy=email.policy.default)
|
||||
|
||||
assert_type(p1, Parser[Message[str, str]])
|
||||
assert_type(p2, Parser[EmailMessage])
|
||||
|
||||
bp1 = BytesParser()
|
||||
bp2 = BytesParser(policy=email.policy.default)
|
||||
|
||||
assert_type(bp1, BytesParser[Message[str, str]])
|
||||
assert_type(bp2, BytesParser[EmailMessage])
|
||||
Reference in New Issue
Block a user