Make email.message.Message generic over the header type (#11732)

Co-authored-by: Avasam <samuel.06@hotmail.com>
This commit is contained in:
Sebastian Rittau
2024-04-23 17:41:10 +02:00
committed by GitHub
parent c13f6e166d
commit 56db30e8eb
3 changed files with 58 additions and 63 deletions

View File

@@ -3,24 +3,34 @@ from collections.abc import Callable
from email.feedparser import BytesFeedParser as BytesFeedParser, FeedParser as FeedParser
from email.message import Message
from email.policy import Policy
from typing import IO
from io import _WrappedBuffer
from typing import Generic, TypeVar, overload
__all__ = ["Parser", "HeaderParser", "BytesParser", "BytesHeaderParser", "FeedParser", "BytesFeedParser"]
class Parser:
def __init__(self, _class: Callable[[], Message] | None = None, *, policy: Policy = ...) -> None: ...
def parse(self, fp: SupportsRead[str], headersonly: bool = False) -> Message: ...
def parsestr(self, text: str, headersonly: bool = False) -> Message: ...
_MessageT = TypeVar("_MessageT", bound=Message, default=Message)
class HeaderParser(Parser):
def parse(self, fp: SupportsRead[str], headersonly: bool = True) -> Message: ...
def parsestr(self, text: str, headersonly: bool = True) -> Message: ...
class Parser(Generic[_MessageT]):
@overload
def __init__(self: Parser[Message[str, str]], _class: None = None, *, policy: Policy = ...) -> None: ...
@overload
def __init__(self, _class: Callable[[], _MessageT], *, policy: Policy = ...) -> None: ...
def parse(self, fp: SupportsRead[str], headersonly: bool = False) -> _MessageT: ...
def parsestr(self, text: str, headersonly: bool = False) -> _MessageT: ...
class BytesParser:
def __init__(self, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> None: ...
def parse(self, fp: IO[bytes], headersonly: bool = False) -> Message: ...
def parsebytes(self, text: bytes | bytearray, headersonly: bool = False) -> Message: ...
class HeaderParser(Parser[_MessageT]):
def parse(self, fp: SupportsRead[str], headersonly: bool = True) -> _MessageT: ...
def parsestr(self, text: str, headersonly: bool = True) -> _MessageT: ...
class BytesHeaderParser(BytesParser):
def parse(self, fp: IO[bytes], headersonly: bool = True) -> Message: ...
def parsebytes(self, text: bytes | bytearray, headersonly: bool = True) -> Message: ...
class BytesParser(Generic[_MessageT]):
parser: Parser[_MessageT]
@overload
def __init__(self: BytesParser[Message[str, str]], _class: None = None, *, policy: Policy = ...) -> None: ...
@overload
def __init__(self, _class: Callable[[], _MessageT], *, policy: Policy = ...) -> None: ...
def parse(self, fp: _WrappedBuffer, headersonly: bool = False) -> _MessageT: ...
def parsebytes(self, text: bytes | bytearray, headersonly: bool = False) -> _MessageT: ...
class BytesHeaderParser(BytesParser[_MessageT]):
def parse(self, fp: _WrappedBuffer, headersonly: bool = True) -> _MessageT: ...
def parsebytes(self, text: bytes | bytearray, headersonly: bool = True) -> _MessageT: ...