mailbox: Fix signature of Mailbox.update method (#3493)

The `update` method calls `self[key] = message` for each `(key, message)`
pair so it also accepts all the same message types as the `__setitem__`
method.  Fix the signature so that the inputs are not restricted to
`Message` instances or to instance of the `_MessageType` type parameter,
but to the more reluctant `_MessageData` type alias.
This commit is contained in:
Tuomas Suutari
2019-11-26 05:45:53 +02:00
committed by Jelle Zijlstra
parent 41bf6a1982
commit 56688240a1

View File

@@ -20,10 +20,10 @@ _MessageType = TypeVar("_MessageType", bound=Message)
_MessageData = Union[email.message.Message, bytes, str, IO[str], IO[bytes]]
class _HasIteritems(Protocol):
def iteritems(self) -> Iterator[Tuple[str, Message]]: ...
def iteritems(self) -> Iterator[Tuple[str, _MessageData]]: ...
class _HasItems(Protocol):
def items(self) -> Iterator[Tuple[str, Message]]: ...
def items(self) -> Iterator[Tuple[str, _MessageData]]: ...
linesep: bytes
@@ -63,7 +63,7 @@ class Mailbox(Generic[_MessageType]):
@overload
def pop(self, key: str, default: _T = ...) -> Union[_MessageType, _T]: ...
def popitem(self) -> Tuple[str, _MessageType]: ...
def update(self, arg: Optional[Union[_HasIteritems, _HasItems, Iterable[Tuple[str, _MessageType]]]] = ...) -> None: ...
def update(self, arg: Optional[Union[_HasIteritems, _HasItems, Iterable[Tuple[str, _MessageData]]]] = ...) -> None: ...
def flush(self) -> None: ...
def lock(self) -> None: ...
def unlock(self) -> None: ...