Reduce code duplication in the email module (#7558)

This commit is contained in:
Alex Waygood
2022-04-06 11:20:14 +01:00
committed by GitHub
parent 1ceb486b75
commit 3c85f36b7f
10 changed files with 31 additions and 35 deletions

View File

@@ -1,23 +1,22 @@
from email import _MessageT
from email.message import Message
from email.policy import Policy
from typing import Callable, Generic, TypeVar, overload
from typing import Callable, Generic, overload
__all__ = ["FeedParser", "BytesFeedParser"]
_M = TypeVar("_M", bound=Message)
class FeedParser(Generic[_M]):
class FeedParser(Generic[_MessageT]):
@overload
def __init__(self: FeedParser[Message], _factory: None = ..., *, policy: Policy = ...) -> None: ...
@overload
def __init__(self, _factory: Callable[[], _M], *, policy: Policy = ...) -> None: ...
def __init__(self, _factory: Callable[[], _MessageT], *, policy: Policy = ...) -> None: ...
def feed(self, data: str) -> None: ...
def close(self) -> _M: ...
def close(self) -> _MessageT: ...
class BytesFeedParser(Generic[_M]):
class BytesFeedParser(Generic[_MessageT]):
@overload
def __init__(self: BytesFeedParser[Message], _factory: None = ..., *, policy: Policy = ...) -> None: ...
@overload
def __init__(self, _factory: Callable[[], _M], *, policy: Policy = ...) -> None: ...
def __init__(self, _factory: Callable[[], _MessageT], *, policy: Policy = ...) -> None: ...
def feed(self, data: bytes) -> None: ...
def close(self) -> _M: ...
def close(self) -> _MessageT: ...